Re: [xsl] Newbie question on XSL transformations: multiple sorts on element attributes

Subject: Re: [xsl] Newbie question on XSL transformations: multiple sorts on element attributes
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 06 Feb 2007 21:45:16 +0100
Rob Newman wrote:
Hi there,

I am relatively new to XSL transformations, so I apologize in advance if this question seems ridiculously simple.

don't, we all have taken our first steps and found walls too steep to climb and pavements so deceptively flat that we slipped. It is always good to ask for help, especially when done so clearly ;-)





-- START SNIPPET --
<xsl:template match="dataloggerlist">
<xsl:element name="dataloggerlist">
<xsl:apply-templates select="datalogger">
<xsl:sort select="param/@id{dlt}" data-type="number" order="descending" />
<xsl:sort select="@name" order="ascending" />
</xsl:apply-templates>
</xsl:element>
</xsl:template>
-- END SNIPPET --
(Note: the datalogger template outputs the data same as before)

This is very strange, as it cannot possibly run, you have a syntax error in your select clause (if you did manage to get it running, can you follow-up with the processor you are using?). The following is in error:


<xsl:sort select="param/@id{dlt}" data-type="number" order="descending" />

Change it to:

<xsl:sort select="param[@id = 'dlt']" />

and all elements with @id = 'dlt' (i.e., attribute nodes containing the exact match to the text 'dlt') will be output firstly.


I would prefer to do this whole process in one step, and avoid having two XSL files that create an interim XML file that just gets transformed again.

and you are right, you won't need to.


Cheers,

-- Abel Braaksma
 http://www.nuntia.nl

Current Thread