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

Conditional xsl:sort and leaving some items out of so

Subject: Conditional xsl:sort and leaving some items out of sorting
From: Abel Braaksma Online <abel.online@xxxxxxxxx>
Date: Wed, 12 Jul 2006 12:27:48 +0200
xsl sort conditional
Hi List!

I have some trouble with "xsl:sort" in XSLT 1.0. FYI, it must run on a client IE, FF, Op etc, using Msxml2.XSLTemplate.5.0 on MS IE and XSLTProcessor() on others. I am well aware of the shortcomings of this approach. Most of the time, sticking strictly to XSLT 1.0 specs gets me a long way.

The logical thing I am trying to achieve is the following (order by cell[1] if $name variable is not equal to 'generic'):

  <xsl:apply-templates select="twz:rows/twz:row" >
      <xsl:if test="$name != 'generic'">
          <xsl:sort select="twz:cell[1]" order="ascending" />
      </xsl:if>
  </xsl:apply-templates>

But this is illegal syntax, as xsl:sort cannot be a child of xsl:if. It doesn't trigger an error either, by the way. I came up with this brute force solution:

  <xsl:if test="$name = 'generic'">
      <xsl:apply-templates select="twz:rows/twz:row" />
  </xsl:if>
  <xsl:if test="$name != 'generic'">
      <xsl:apply-templates select="twz:rows/twz:row" >
          <xsl:sort select="twz:cell[1]" order="ascending" />
      </xsl:apply-templates>
  </xsl:if>

But actually I hoped to be able to do something like this eventually:

<xsl:apply-templates select="twz:rows/twz:row" >
<xsl:sort select="($name = 'generic' and position()) or twz:cell[1]" order="ascending" />
</xsl:apply-templates>



Is my approach the "xslt way" of doing things, or is there a different way of doing this? Is there a pattern available about this? In addition, I would like to ask how to extend the solution above to order the list in such a way that all is ordered except items that have the value "None" or "All". These should end up on the bottom of the list.


Any help or pointers would be appreciated. I tried Michael Kays books, but these emphasize on XSLT 2.0 and I couldn't find how to do this better than above.

Cheers,
Abel Braaksma
Nuntia B.V.
www.nuntia.nl (online July 17)

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.