Subject: Re: [xsl] Sorting a XML file with XSL From: Florent Georges <lists@xxxxxxxxxxxx> Date: Wed, 24 Oct 2007 10:47:45 +0200 (CEST) |
Buddhi Dananjaya wrote: Hi > Following is my sample XML file, I want to sort this base on > <comment> tag and make a new XML file using a style sheet You can use the Modified Identity pattern: <xsl:output indent="yes"/> <!-- Identity transform --> <xsl:template match="node()"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates select="node()"/> </xsl:copy> </xsl:template> <xsl:template match="root"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates select="*"> <xsl:sort select="data/comment"/> </xsl:apply-templates> </xsl:copy> </xsl:template> The data/comment contents are not unique. If you want to order a second field to perform more precise sorting, you can do so using a second xsl:sort instruction. For instance, if you want to sort on comment then on @name: <xsl:apply-templates select="*"> <xsl:sort select="data/comment"/> <xsl:sort select="data/@name"/> </xsl:apply-templates> Regards, --drkm _____________________________________________________________________________ Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Sorting a XML file with XSL, Buddhi Dananjaya | Thread | Re: [xsl] Sorting a XML file with X, Buddhi Dananjaya |
[xsl] Sorting a XML file with XSL, Buddhi Dananjaya | Date | Re: [xsl] Date, Number Format, Andrew Welch |
Month |