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

Re: [xsl] Sorting a XML file with XSL


Subject: Re: [xsl] Sorting a XML file with XSL
From: Buddhi Dananjaya <buddhi@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 24 Oct 2007 15:01:38 +0530

I tried with the XSL posted. But after transformation I am again getting same XML as out put (not sorted)

Why it is mentioned as comment blocks are not uniques, as I feel they are unique.. Main.cs, Text.cs, etc.


Florent Georges wrote:
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
Keywords