Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting in XSL

Status
Not open for further replies.

funnix

Programmer
Jan 8, 2002
1
SG
Hi all

I need your help.

The question is , i was trying to sort this xml information in the order of name which is

CW04
CR01
CR04
CA01.

Below is the extract of the xml file.


<category>
<name>CR01</name>
<description>CR01</description>
<grade>CR01</grade>
<tendering>CR01</tendering>
</category>
<category>
<name>CW04</name>
<description>CW04</description>
<grade>CW04</grade>
<tendering>CW04</tendering>
</category>
<category>
<name>CR04</name>
<description>CR04</description>
<grade>CR04</grade>
<tendering>CR04</tendering>
</category>
<category>
<name>CA01</name>
<description>CA01</description>
<grade>CA01</grade>
<tendering>CA01</tendering>
</category>

The sorted result is :

workhead description grade tendering

CW04 CW04 CW04 CW04
CR01 CR01 CR01 CR01
CR04 CR04 CR04 CR04
CA01 CA01 CA01 CA01

The order(a) explain in this way
CW
CR
CA

Howver each individual might have 01 to 04. so need to sort in the order of a
above follow by the sequence of number thats mean
CW01
CW02
CW03
CW04
CR01
CR02
and etc.

can anyone please help? how do i code for the XSL?
 
The following should do it. And, if you wanted to sub-sort first by name and then by description, you would just add another <xsl:sort select=&quot;description&quot;/> immediately after the first <xsl:sort> tag.

<xsl:template match=&quot;/&quot;>
<table>
<tr>
<td>Workhead</td>
<td>Description</td>
<td>Grade</td>
<td>Tendering</td>
</tr>
<xsl:for-each select=&quot;/category&quot;>
<xsl:sort select=&quot;name&quot;/>
<xsl:call-template name=&quot;display&quot;/>
</xsl:for-each>
</table>
</xsl:template>

<xsl:template name=&quot;display&quot;>
<tr>
<td><xsl:value-of select=&quot;name&quot;/></td>
<td><xsl:value-of select=&quot;description&quot;/></td>
<td><xsl:value-of select=&quot;grade&quot;/></td>
<td><xsl:value-of select=&quot;tendering&quot;/></td>
</tr>
</xsl:template>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top