xsl-list
[Top] [All Lists]

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

2008-07-19 23:56:35
I am very inexperienced, using XSLT 2.0 with Saxon B9.0.0.6 in Oxygen on Windows Vista. I have Michael Kay's book, but do not know enough to find the answer to my question on my own.

I want to do a simple sort without losing either elements or attributes. The xls style sheet I have written works, but there must be a more succinct method. One element <Cat> has four attributes (two optional), the other <Person> has one optional attribute. When the templates for <Cat> and <Person> are not present in my style sheet, I lose the attributes but not the elements themselves.

Is the answer somewhere in apply-templates? Without the two templates, when I tried <xsl:apply-templates select="@* | node()"/>, I got the value of the attributes as a list within the start tags but without their names. Did I miss something?

Thanks for any help,
Mark

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">
   <xsl:output method ="xml" />
   <xsl:strip-space elements="*"/>

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

   <xsl:template match="Cat">
       <xsl:element name="Cat">
           <xsl:attribute name="pofis">
               <xsl:value-of  select="@pofis" />
           </xsl:attribute>
           <xsl:attribute name="pofis-number">
               <xsl:value-of select="@pofis-number" />
           </xsl:attribute>
           <xsl:if test="@pofis-range">
           <xsl:attribute name="pofis-range">
               <xsl:value-of select="@pofis-range" />
           </xsl:attribute>
           </xsl:if>
           <xsl:if test="@pofis-prefix">
           <xsl:attribute name="pofis-prefix">
               <xsl:value-of select="@pofis-prefix" />
           </xsl:attribute>
           </xsl:if>
           <xsl:value-of  select="node()" />
       </xsl:element>
   </xsl:template>

   <xsl:template match="Person">
       <xsl:element name="Person">
           <xsl:if test="@is-author">
           <xsl:attribute name="is-author">
               <xsl:value-of select="@is-author" />
           </xsl:attribute>
           </xsl:if>
           <xsl:value-of select="node()"/>
</xsl:element>

--~------------------------------------------------------------------
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>
--~--