This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: sort problem
- From: Peter Davis <pdavis152 at attbi dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Cc: aruniima dot chakrabarti at iflexsolutions dot com
- Date: Wed, 4 Sep 2002 22:11:55 -0700
- Subject: Re: [xsl] sort problem
- References: <CBF6DBC01C62C64DA820DCFCD48E05C8AEFC08@fmg-nt.spz.i-flex.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
On Wednesday 04 September 2002 21:28, aruniima.chakrabarti@iflexsolutions.com
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