|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Sorting subtrees based on their maximum 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








