[Home] [By Thread] [By Date] [Recent Entries]
At 2013-07-31 08:30 -0400, Rick Quatro wrote:
I have a series of nested steps that I want to reverse sort at each level. Here is what I am starting with: ... This is what I want to get: ... My steps could be nested up to five levels, so I tried to call a template recursively, but it is not giving me exactly what I want. When I think of recursion, I try to think of how applying templates would work ... and the end result is really quite compact. I hope the code below helps. . . . . . . . Ken T:\ftemp>type rick.xml
<?xml version="1.0"?>
<steps>
<step>A
<step>(1)</step>
<step>(2)
<step>(a)</step>
<step>(b)</step>
<step>(c)</step>
</step>
<step>(3)</step>
</step>
<step>B</step>
<step>C</step>
</steps>
T:\ftemp>xslt rick.xml rick.xsl
<?xml version="1.0" encoding="utf-8"?>
<steps>
<step>C</step>
<step>B</step>
<step>A
<step>(3)</step>
<step>(2)
<step>(c)</step>
<step>(b)</step>
<step>(a)</step>
</step>
<step>(1)</step>
</step>
</steps>
T:\ftemp>type rick.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"><xsl:output indent="yes"/> <xsl:template match="steps | step">
<xsl:copy>
<xsl:apply-templates select="text()[normalize-space()]"/>
<xsl:apply-templates select="step">
<xsl:sort select="position()" order="descending"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template></xsl:stylesheet> T:\ftemp> -- Public XSLT, XSL-FO, and UBL classes in the Netherlands Oct 2013 | Public XSLT, XSL-FO, UBL and code list classes in Australia Oct 2013 | Contact us for world-wide XML consulting and instructor-led training | Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm | Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ | G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx | Google+ profile: https://plus.google.com/116832879756988317389/about | Legal business disclaimers: http://www.CraneSoftwrights.com/legal |
|

Cart



