|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: SUMMARY: Re: Sorting on a variable
> The general solution I'm using is to clone the source tree, adding to it
> for each product a new child element containing the calculated value
> (USD-equivalent currency figures, in this case). This clone (an RTF,
> converted to a node-set using your favorite processor's node-set()
> extension function) then gets sorted on the created element. Works like a
> champ. (Sample code below.)
Although actually in this example you can do it without need for
extension namespaces (or variables). Just sort on a suitably constructed
xpath. Something not unlike this
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:template match="/">
<html>
<head><title>Sorting an RTF</title></head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<!-- Template rule for root element <products> -->
<xsl:template match="products">
<table border="1">
<tr>
<th>Name/Version</th>
<th>Price / Curr</th>
<th>Price (USD)</th>
</tr>
<xsl:apply-templates select="product">
<xsl:sort select="
concat('0',price[@curr='USD']) +
concat('0',price[@curr='GBP']) *1.47275 +
concat('0',price[@curr='EU']) * 0.864379 "
data-type="number" />
</xsl:apply-templates>
</table>
</xsl:template>
<xsl:template match="product">
<tr>
<td valign="top"><xsl:value-of select="name"/></td>
<td align="right">
<xsl:value-of select="price"/> / <xsl:value-of select="price/@curr"/>
</td>
<td align="right"><xsl:value-of select="
format-number(
concat('0',price[@curr='USD']) +
concat('0',price[@curr='GBP']) *1.47275 +
concat('0',price[@curr='EU']) * 0.864379 ,
'#,##0.00')
"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








