Re: [xsl] What is the simplest method for using xsl:sort without losing attribute names and values?

Subject: Re: [xsl] What is the simplest method for using xsl:sort without losing attribute names and values?
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Mon, 21 Jul 2008 13:55:41 +0200
Mark Wilson wrote:

In the example below, only one <Item> is shown. I tried the template you suggested.

I suggested to start with the identity transformation template and then to add a template or templates to perform the changes you want.
So you would at least need


<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="1.0">

  <xsl:strip-space elements="*"/>
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="List">
       <xsl:copy>
           <xsl:apply-templates select="@*"/>
           <xsl:apply-templates>
               <xsl:sort select="Article/Year" />
               <xsl:sort select="Article/IssueNumber"/>
               <xsl:sort select="Article/Page" />
           </xsl:apply-templates>
       </xsl:copy>
   </xsl:template>

</xsl:stylesheet>

that way attributes (like pofis) are copied trough and the child elements of List elements, the Item elements, are sorted on Article/Year, Article/IssueNumber, Artice/Page.

The only change you probably need is to adapt the xsl:sort instructions to add the data type e.g.
<xsl:sort select="Article/Page" data-type="number"/>



--


	Martin Honnen
	http://JavaScript.FAQTs.com/

Current Thread