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

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


Subject: RE: [xsl] :xsl matching/sorting recursively by attribute:
From: "Yates, Danny (ANTS)" <danny.yates@xxxxxxxxxx>
Date: Tue, 4 Mar 2003 09:29:12 -0000

Hi,

I haven't looked at the table formatting, but hopefully this will start
you on your way...

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>

  <xsl:template match="/">
    <xsl:apply-templates select="//*[@task]" mode="sorted-tasks">
      <xsl:sort select="@task"/>
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="*" mode="sorted-tasks">
    <xsl:copy-of select="."/>
  </xsl:template>
</xsl:stylesheet>

Note that I use match="*" and a mode in the second template to avoid having
to
specify the match pattern (//*[@task]) in two places which would be a
maintenance
nightmare if the stylesheet were much bigger.

Rgds,

Dan.


-----Original Message-----
From: Mac Martine [mailto:email@xxxxxxxxxxxxxxxx]
Sent: 03 March 2003 19:33
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] :xsl matching/sorting recursively by attribute:



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


***************************************************************************
This communication (including any attachments) contains confidential information.  If you are not the intended recipient and you have received this communication in error, you should destroy it without copying, disclosing or otherwise using its contents.  Please notify the sender immediately of the error.

Internet communications are not necessarily secure and may be intercepted or changed after they are sent.  Abbey National Treasury Services plc does not accept liability for any loss you may suffer as a result of interception or any liability for such changes.  If you wish to confirm the origin or content of this communication, please contact the sender by using an alternative means of communication.

This communication does not create or modify any contract and, unless otherwise stated, is not intended to be contractually binding.

Abbey National Treasury Services plc. Registered Office:  Abbey National House, 2 Triton Square, Regents Place, London NW1 3AN.  Registered in England under Company Registration Number: 2338548.  Regulated by the Financial Services Authority (FSA).
***************************************************************************


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



Current Thread
Keywords
xml