[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] :xsl matching/sorting recursively by attribute:


Subject: [xsl] :xsl matching/sorting recursively by attribute:
From: "Mac Martine" <email@xxxxxxxxxxxxxxxx>
Date: Mon, 3 Mar 2003 11:32:34 -0800

Hello-
 I am trying to match all elements with an attribute 'task' recursively
throughout the tree. I got that part working, but I have been unable to
get it 'sorted' how I want.
I want all recursive elements with a 'task' attribute to be sorted by
the value of that attribute, and displayed.

So a simple xml file for this might look like:

<desktop id="desktop">
	<lineEdit task="3"/>
	<panel id="main">
		<panel id="toolbar">
			<button task="2">Back</button>
			<button task="1">Foward</button>
		</panel>
	</panel>
</desktop>

So, next is the xsl. This is as close I have been able to get....
Can anyone help solve this one?
Thanks a lot!
-Mac

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
	<body>
		<table width="80%">
			<xsl:apply-templates />
		</table>
	</body>
</xsl:template>

<xsl:template match="*">

	<xsl:for-each select="*[@task>0]">
		<xsl:sort select="@task"/>
		<xsl:call-template name="tasks"/>
	</xsl:for-each>

	<xsl:apply-templates select='*'/>
</xsl:template>

<xsl:template name="tasks">

		<tr>
			<td width="5%">
				<xsl:value-of select="@task"/>
			</td>
		</tr>

</xsl:template>

</xsl:stylesheet>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords
xml