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

Re: To simulate SORT inside a xsl:choose condition

Subject: Re: To simulate SORT inside a xsl:choose condition
From: Greg Faron <gfaron@xxxxxxxxxxxxxxxxxx>
Date: Mon, 29 Apr 2002 16:38:42 -0600
xsl sort inside test condition
At 04:15 PM 4/29/2002, you wrote:
Hi all ,

I know that the rule to sort should be immediately after <xsl:for-each >
I am in a situation where i have to read the criteria to sort from some some node in the beginning of XML
and based on which i need to make a decision to sortBY corresponding node somewhere down the line....



But as you know the following way doesnt work ...


<xsl:for-each select="somenode">
    <xsl:choose>
       <xsl;when test="$prevnode = 'criteriavalue' ">
             <xsl:sort  order="ascending"  select="node_to_be_sorted"/>
      </xsl:when>
    </xsl:choose>

</xsl:for-each>

Note: dont worry about syntax check on this ...

Is there a way to sneak around and get this Sorting to work based on some criteria ...Or any other work arounds, suggestions?

I think the answer depends on what the tests are (e.g. What is $prevnode?). If your test is based on some value of the nodes selected by the for-each, then you're asking to re-order everything after you get and test the first item. This is not good. The workaround here is to select items based on that value in the original for-each selection.


If, on the other hand, your tests are based on some external value, it's pretty easy. You just create multiple for-each's and only execute the one you need.
<xsl:choose>
<xsl:when test="$prevnode='criteriavalue1'">
<xsl:for-each select="somenode">
<xsl:sort order="ascending" select="node_to_be_sorted"/>
</xsl:for-each>
</xsl:when>
<xsl:when test="$prevnode='criteriavalue2'">
<xsl:for-each select="somenode">
<xsl:sort order="descending" select="other_node_to_be_sorted"/>
</xsl:for-each>
</xsl:when>
</xsl:choose>



Greg Faron Integre Technical Publishing Co.



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.