xsl-list
[Top] [All Lists]

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

2008-07-21 04:56:14
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/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--