[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Sorting nested steps

Subject: Sorting nested steps
From: "Rick Quatro" <rick@xxxxxxxxxxxxxx>
Date: Wed, 31 Jul 2013 08:30:10 -0400
 Sorting nested steps
Hi,

I have a series of nested steps that I want to reverse sort at each level.
Here is what I am starting with:

<?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>

This is what I want to get:

<?xml version="1.0"?>
<steps>
    <step>C</step>
    <step>B</step>
    <step>A
        <step>(3)</step>
        <step>(2)
            <step>(c)</step>
            <step>(b)</step>
            <step>(a)</step>
        <step>(1)</step>
        </step>
    </step>
</steps>

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. Here is my
stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:output method="xml" indent="yes"/>
    
    <xsl:template match="/steps">
        <xsl:call-template name="sort-steps"/>
    </xsl:template>
    
    <xsl:template name="sort-steps">
        <xsl:for-each select="step">
            <xsl:sort order="descending"/>
            <xsl:copy><xsl:value-of select="."/></xsl:copy>
            <xsl:call-template name="sort-steps"/>
        </xsl:for-each>
    </xsl:template>
    
</xsl:stylesheet>

Thank you in advance.

Rick

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.