XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
RE: [xml-dev] Schematron and comma as a decimal delimiter

Hi,

Le lundi 04 septembre 2006 à 12:24 +0100, Michael Kay a écrit :
> > The problem is that a comma has been used as a decimal 
> > delimiter and sum() function seems to work only with dots. I 
> > tested translate() function but it seems to work only with a 
> > single node, not with a node-set. Is there any workaround 
> > available for my problem?
> 
> Like so many things (despite ERH's views) this one is so much easier in
> XPath 2.0:
> 
> sum(for $x in ... return number(translate($x, '.', ',')))
> 
> If you're stuck with 1.0, google for "XSLT sum computed values". The
> solutions fall into four categories: (1) multi-phase transformations, (2)
> higher-order functions (FXSL), (3) recursion over the items being summed,
> (4) extension functions. None of these can conveniently be used in an XPath
> (as distinct from XSLT) context.

Some of these options happen to be compatible with ISO Schematron.

As soon as implementations supporting XSLT/XPath 2.0 bindings will be
available, you will be able to use XPath 2.0 expressions such as your
"sum(for $x in ... return number(translate($x, '.', ',')))" in test
attributes.

Right now, with an implementation supporting EXSLT (such as Amara,
http://uche.ogbuji.net/tech/4suite/amara/), you can use the dyn:map
function (http://www.exslt.org/dyn/functions/map/dyn.map.html) and
write:

<schema xmlns="http://purl.oclc.org/dsdl/schematron"; queryBinding="exslt">
  <title>Sums with commas</title>
  <ns prefix="dyn" uri="http://exslt.org/dynamic"/>
  <pattern>
    <rule context="Invoice">
      <let name="sum"
        value="sum(dyn:map(InvoiceRow/RowAmount, 'translate(., &quot;,&quot;, &quot;.&quot;)'))"/>
      <let name="total"
        value="translate(TotalAmount, &quot;,&quot;, &quot;.&quot;)"/>
      <assert test="$sum = $total"> TotalAmount (<value-of select="$total"/>) doesn't match the sum
        of RowAmounts (<value-of select="$sum"/>) </assert>
    </rule>
  </pattern>
</schema>

(You'll need to use the latest 4Suite CVS if you want to try that,
though).

Eric

> Michael Kay
> http://www.saxonica.com/
> 
> 
-- 
GPG-PGP: 2A528005
Le premier annuaire des apiculteurs 100% XML!
                                                http://apiculteurs.info/
------------------------------------------------------------------------
Eric van der Vlist       http://xmlfr.org            http://dyomedea.com
(ISO) RELAX NG   ISBN:0-596-00421-4 http://oreilly.com/catalog/relax
(W3C) XML Schema ISBN:0-596-00252-1 http://oreilly.com/catalog/xmlschema
------------------------------------------------------------------------

Ceci est une partie de message=?ISO-8859-1?Q?num=E9riquement?= =?ISO-8859-1?Q?_sign=E9e?=



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS