[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Variables and constants

Subject: Re: Variables and constants
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 25 Feb 2000 14:59:24 GMT
xslt variables constants
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.