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)
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