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(., ",", ".")'))"/> <let name="total" value="translate(TotalAmount, ",", ".")"/> <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?=