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

Re: SUMMARY: Re: Sorting on a variable

Subject: Re: SUMMARY: Re: Sorting on a variable
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 17 Oct 2000 11:26:43 GMT
cost summary of sorting
> 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

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.