Subject: Re: SUMMARY: Re: Sorting on a variable From: David Carlisle <davidc@xxxxxxxxx> Date: Tue, 17 Oct 2000 11:26:43 GMT |
> 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
SUMMARY: Re: Sorting on a variable, John E. Simpson | Thread | Re: SUMMARY: Re: Sorting on a varia, John E. Simpson |
RE: apply-template question..., Kay Michael | Date | translating xml:lang attribute, Matthias O. Will |
Month |