[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: Variables and constants
Subject: Re: Variables and constants From: David Carlisle <davidc@xxxxxxxxx> Date: Fri, 25 Feb 2000 14:59:24 GMT |
PS > Clearly this was an intentional design decision, but it makes it impossible > to do any kind of simplistic calculation (e.g. totalling a shopping cart > that has price and quantity information for each item) without resorting to > recursion. The fact that some calculations are rather awkward in xslt is not really due so much to the functional style, as to the fact that the main `function' expression that you have available, namely the template returns a result of a type `result tree fragment' that is opaque to the expression language. If the restrictions on querying into rtf were not there or (equivalently) a function is provided to coerce an rtf back to a node set so that it may be queried, then many things become much simpler. So here is your basket calculation sans recursion but with xt:node-set <x> <thing><quantity> 1</quantity><price> 2</price></thing> <thing><quantity> 4</quantity><price> 5</price></thing> <thing><quantity> 3</quantity><price>10</price></thing> <thing><quantity> 2</quantity><price> 1</price></thing> </x> <total xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0" xmlns:xt="http://www.jclark.com/xt" > <xsl:variable name="x"> <xsl:for-each select="x/thing"> <a><xsl:value-of select="quantity * price"/></a> </xsl:for-each> </xsl:variable> <xsl:value-of select="sum(xt:node-set($x)/a)"/> </total> xt basket.xml basket.xsl <?xml version="1.0" encoding="utf-8"?> <total>54</total> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Variables and constants, Lars Marius Garshol | Thread | RE: Variables and constants, Kay Michael |
Re: Variables and constants, Lars Marius Garshol | Date | Re: Trying to learn XSL, Juergen Hermann |
Month |
Keywords