Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 14th, 2011, 02:21 PM
Authorized User
 
Join Date: Apr 2011
Posts: 22
Thanks: 4
Thanked 0 Times in 0 Posts
Default XSL sort on identity transform

How to perform a xsl sort on an attribute, when performing an identity transform?

Sample Input:
<A a="1"/>
<A a="3"/>
<A a="4"/>
<A a="2"/>

Expected Output:
<A a="1"/>
<A a="2"/>
<A a="3"/>
<A a="4"/>
 
Old October 14th, 2011, 03:57 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Well unless every element has the exact same attribute name you wouldn't usually put sorting inside an identity template.

xsl:sort goes within either a xsl:for-each or a xsl:apply-templates, so you have to be sorting from outside the elements you are sorting. Your identity would look like this:

Code:
<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*"/>
    <xsl:apply-templates select="node()">
      <xsl:sort select="@a"/>
    </xsl:apply-templates>
  </xsl:copy>
</xsl:template>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Transform an XSL sheet khanman225 XSLT 8 July 6th, 2006 10:21 AM
Getting @@IDENTITY in Row Transform afward SQL Server DTS 2 September 28th, 2005 09:56 AM
Unable to sort using xsl sort command sly_jimmy_boy XSLT 3 June 17th, 2005 05:15 AM
How can XSL transform XHTML data into fragments? lamwh XSLT 0 April 19th, 2004 10:15 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.