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

Re: [xsl] sort problem


Subject: Re: [xsl] sort problem
From: Peter Davis <pdavis152@xxxxxxxxx>
Date: Wed, 4 Sep 2002 22:11:55 -0700

On Wednesday 04 September 2002 21:28, aruniima.chakrabarti@xxxxxxxxxxxxxxxxxx 
wrote:
>  Thanks David... but i still confused...if i do <xsl:apply-templates
> select="@* | * | text()"> or <xsl:apply-templates select="@* | * |
> node()">, the output doesnot contain any of the attributes. Please help in
> getting the required output.

The problem is probably that if you output attributes, they must be output 
immediately after the element to which they belong (you can't output any 
other elements or text before your attributes).

Since you are sorting by the name() of the nodes, the text() nodes will always 
be output first, since the name of a text node is "#text".  The hash mark (#) 
will be sorted alphabetically before the names of your attributes.

The solution could be to apply-templates to attributes and other nodes 
separately.  It doesn't make any sense to sort the output of attributes 
anyway (since attributes don't have any defined order).

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

Let me know if this solves your problem, and HTH.

-- 
Peter Davis

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread