[Home] [By Thread] [By Date] [Recent Entries]
At 2007-11-28 17:04 -0500, Davis Ford wrote:
Hi, consider the following example: ... I want to sort it as such ... I am trying to come up with a generic XSLT solution that does not use explicit element names, but only uses the sort select="name()", and it should be recursive such that if say, element <A1> contained further elements, then they would also be sorted by element name. Am I missing something? This is a variant of a one-template identity transform. I hope the example below helps. . . . . . . . . . . Ken t:\ftemp>type davis.xml
<Collection>
<CollectionB>
<B2></B2>
<A2></A2>
<A1></A1>
<B1 typeName="2"></B1>
<B1 typeName="1"></B1>
</CollectionB>
<CollectionA>
<B2></B2>
<A2></A2>
<A1></A1>
<B1></B1>
</CollectionA>
</Collection>t:\ftemp>type davis.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"><xsl:output indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()">
<xsl:sort select="name(.)"/>
<xsl:sort select="@typeName"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template></xsl:stylesheet>
t:\ftemp>xslt davis.xml davis.xsl con
<?xml version="1.0" encoding="utf-8"?>
<Collection>
<CollectionA>
<A1/>
<A2/>
<B1/>
<B2/>
</CollectionA>
<CollectionB>
<A1/>
<A2/>
<B1 typeName="1"/>
<B1 typeName="2"/>
<B2/>
</CollectionB>
</Collection>
t:\ftemp>
|

Cart



