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

Sorting subtrees based on their maximum depth.

Subject: Sorting subtrees based on their maximum depth.
From: Mike Trotman <mike.trotman@xxxxxxxxxxxxx>
Date: Sat, 26 Jun 2004 17:14:23 +0100
xsl max depth
Hi.

I have XML documents containing hierarchical ly recursive SUBTREES.
(eg:
<XML>
....
<SUBTREE>
...<SUBTREE>
......<SUBTREE>
.....etc....
......</SUBTREE>
......<SUBTREE>
.....etc....
......</SUBTREE>
....</SUBTREE>
...<SUBTREE>
......<SUBTREE>
.....etc....
......</SUBTREE>
....</SUBTREE>
</SUBTREE>
...
</XML>

I need to recursively sort these SUBTREES based on the maximum depth of descendant elements that they contain.

I am currently doing this in two passes.
In the 1st pass I compute and assign a 'DEPTH' attribute to each SUBTREE using:


<xsl:variable name='curr_depth' select='count(ancestor::*'/>
<xsl:variable name='DEPTH'>
<xsl:for-each select='.//*[not(child::*)]'>
<xsl:sort select='count(ancestor::*) - $curr_depth' data-type='number' order='descending'/>
<xsl:if test='position() = 1'><xsl:value-of select='count(ancestor::*) - $curr_depth'/></xsl:if>
</xsl:for-each>
</xsl:variable>


and then I reprocess the new document using normal sorting on the '@DEPTH' attribute.

I wondered if there is a way to do this in one-pass - and to avoid doing those ancestor counts twice.

Any help greatly appreciated.

--
Datalucid Limited
8 Eileen Road
South Norwood
London SE25 5EJ
/ tel :0208-239-6810
mob: 0794-725-9760
email: mike.trotman@xxxxxxxxxxxxx
/
UK Co. Reg:   	4383635
VAT Reg.:   	798 7531 60



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.