Subject: Re: [xsl] generic sort based on attribute names From: "Joris Gillis" <roac@xxxxxxxxxx> Date: Sun, 23 Jan 2005 10:42:29 +0100 |
Hi,Suppose <root> <e b="bb" y="yy"/> <e z="zz" a="aa"/> </root> is the XML I want to sort. The result of the sort should be <root> <e a="aa" z="zz" /> <e b="bb" y="yy" /> </root> Thus the attributes within an element are sorted and then the key used for sorting elements would be: 'az' and 'by' respectively (thus 'az' < 'by').
<xsl:template match="root"> <xsl:variable name="sortkey"> <xsl:apply-templates select="e" mode="sortkey"/> </xsl:variable> <xsl:copy> <xsl:apply-templates select="e" > <xsl:sort select="substring($sortkey,position()*2 - 1, 2)"/> </xsl:apply-templates> </xsl:copy> </xsl:template>
<xsl:template match="e" mode="sortkey"> <xsl:apply-templates select="@*" mode="sortkey"> <xsl:sort select="." data-type="string"/> </xsl:apply-templates> </xsl:template>
<xsl:template match="@*" mode="sortkey"> <xsl:value-of select="local-name()"/> </xsl:template>
<xsl:template match="e"> <xsl:copy> <xsl:apply-templates select="@*" > <xsl:sort select="." data-type="string"/> </xsl:apply-templates> </xsl:copy> </xsl:template>
<xsl:template match="@*"> <xsl:copy-of select="."/> </xsl:template>
regards, -- Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041) Deserta faciunt et innovationem appelant
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] generic sort based on attribu, Chaitanya Desai | Thread | Re: [xsl] generic sort based on att, Dimitre Novatchev |
RE: [xsl] namespace-alias problem, Touchtel | Date | Re: [xsl] namespace-alias problem, Geert Josten |
Month |