June 2008
Intermediate to advanced
986 pages
27h 8m
English
Our original stylesheet had to use recursion to
calculate the total of each purchase order. We passed all of the
<item> elements to a recursive template, which returned the total for
the purchase order after processing all of the <item>s. In XSLT 2.0, we can use a
simple XPath expression to do all that work for us. Here’s the single
line of code:
<xsl:value-of
select="format-number(sum(items/item/(qty * price)),
'$#,###.00')"/>That’s it. XPath 2.0’s support for mathematical expressions inside path expressions makes this ridiculously easy. We replaced maybe 20 lines of code with just 1.
Read now
Unlock full access