|
Subject: Re: [xsl] To simulate SORT inside a xsl:choose condition From: "KUMAR NINGASHETTY" <kningashetty@xxxxxxxxxxxxxxxx> Date: Mon, 29 Apr 2002 19:36:38 -0400 |
Thanx for all your replies ...
As per Dion and Faron suggested...I have to loop twice or applytemplates twice inorder to achieve this ..The processing inside this for-loop or apply-templates that goes in is lot in my case...so i was trying to avoid this...
I tried Joerg's idea....I am getting syntax errors...
To make things clear ...THis is what i have ...
<data>
<criteria>
<sortby><![CDATA[city]]></sortBy>
</criteria>
<loo>
<reg id="204">
<region_name><![CDATA[Region 5]]></region_name>
<username userid="1017"><![CDATA[name1]]></username>
<username userid="8248"><![CDATA[name2]]></username>
</reg>
</loo>
<company>
<regions useridref="1017">
<comp_name>aaa</comp_name>
<city>york</city>
</regions>
<regions useridref="8248">
<comp_name>bbb</comp_name>
<city>jersey</city>
</regions>
</company>
</data>
I have written XSL to display city, companyname in Table structure .based on the criteria node's sorting i will have to either sort the data by City or Comp_name
when it appears for the first time ...
I tried this ..globally i did
<xsl:variable name="sortmethod" select="//criteria/sortby">
SOmewhere down in my template where i write xsl:for i do this ....
<xsl:for-each select="//regions">
<xsl:sort order="ascending" select="name()=$sortmethod"/>
</xsl:for-each>
Does that work??
-kumar
>>> gfaron@xxxxxxxxxxxxxxxxxx 04/29/02 06:38PM >>>
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
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] To simulate SORT inside a, Joerg Heinicke | Thread | Re: [xsl] To simulate SORT inside a, Joerg Heinicke |
| [xsl] Accessing nodes via variables, Manish M. Shah | Date | [xsl] a newbie struggling, pandianoliver |
| Month |