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

Re: Sorting on a variable

Subject: Re: Sorting on a variable
From: Mike Brown <mike@xxxxxxxx>
Date: Mon, 16 Oct 2000 13:25:22 -0600 (MDT)
xml sortkey
mxmodi@xxxxxxxxxxxxxxx wrote:
> I have a similar problem with sort where I want the table to sort as per
> user interaction. Kind of like on of the price comparison sites where you
> can sort either by category, price, or availability, etc. Only thing is I
> DO NOT want to use the MS ActiveX Object in XSL. I want to stick to XSLT.

Would an externally assigned parameter suffice? When you invoke the
transformation, your XSLT processor should give you a way to assign and
pass in the parameter. For example,

java com.icl.saxon.StyleSheet foo.xml foo.xsl sortKey=price

would assign the string 'price' to the parameter sortKey. Then in the
stylesheet you could refer to $sortKey. i.e., add as a child of
xsl:stylesheet:

<xsl:param name="sortKey"/>

and then in the templates you can do things like this, depending on the
source tree's schema:

<xsl:for-each select="itemForSale">
  <xsl:sort select="*[name() = $sortKey]"/>
  ...
</xsl:for-each>

or 

<xsl:choose>
  <xsl:when test="$sortKey = 'category'">
    <xsl:apply-templates select="itemForSale">
      <xsl:sort select="ancestor::category[1]"/>
    </xsl:apply-templates>
  </xsl:when>
  <xsl:when test="$sortKey = 'price'">
    <xsl:apply-templates select="price"/>
  </xsl:when>
  ...
</xsl:choose>

   - Mike
____________________________________________________________________
Mike J. Brown, software engineer at         My XML/XSL resources:
webb.net in Denver, Colorado, USA           http://www.skew.org/xml/


 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.