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: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Sun, 20 Jul 2008 14:16:23 +0530
Can you please post a sample input and the desired output. It'll help
us to suggest the answer.

Also, in your templates, you have written, <xsl:value-of
select="node()"/>. What do you expect to achieve here?

I have another curiosity. What do you want to achieve with the
templates, Cat and Person? Probably, there are simpler constructs to
achieve what you want. But we can suggest something, only after you
clarify a bit more.

On 7/20/08, Mark Wilson <mark@xxxxxxxxxxxx> wrote:
> 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="";
> 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>

Mukul Gandhi

Current Thread