[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Dave,
This is less sophisticated, graceful and powerful than Dimitre's solution, but perhaps requires less sophistication, grace and power to maintain (so a hacker may prefer it):
It uses the trick of sorting all the nodes in the document by how deep they are, and then throwing away all but the first, reporting its depth.
Brutal, inefficient, and poor to scale, but it should work. (Nor does it tell you which nodes are deepest, as Dimitre's function does.)
At 03:05 PM 5/10/2002, you wrote:
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Re: [xsl] Finding the maximum depth from a node
Subject: Re: [xsl] Finding the maximum depth from a node From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Fri, 10 May 2002 16:31:33 -0400 |
Dave,
This is less sophisticated, graceful and powerful than Dimitre's solution, but perhaps requires less sophistication, grace and power to maintain (so a hacker may prefer it):
<xsl:template name="deepest"> <xsl:for-each select="//folder"> <!-- sorry everyone! --> <xsl:sort select="count(ancestor-or-self::*)" order="descending"/> <xsl:if test="position()=1"> <xsl:value-of select="count(ancestor-or-self::*)"/> </xsl:if> </xsl:if> </xsl:template>
It uses the trick of sorting all the nodes in the document by how deep they are, and then throwing away all but the first, reporting its depth.
Brutal, inefficient, and poor to scale, but it should work. (Nor does it tell you which nodes are deepest, as Dimitre's function does.)
Cheers, Wendell
At 03:05 PM 5/10/2002, you wrote:
Ok, I have basically almost a file structure in an xml document, something like this:
<root> <folder name="1"> <folder name="2"/> <folder name="3"> <folder name="4"/> </folder> <folder name="5"> <folder name="6"> <folder name="7"> <folder name="8"/> </folder> </folder> </folder> </root>
I need to be able to find out how deep the nodes go, i.e. when the template has matched root, I need to work out how deep the deepest folder is (folder 8 in this case). I know how to calculate a depth from a nodes context, but not the depth of its children.
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Finding the maximum depth fro, Dave Townsend | Thread | Re: [xsl] Finding the maximum depth, Jeni Tennison |
RE: [xsl] Xalan Rounding, Stuart Celarier | Date | [xsl] Re: Finding the maximum depth, Dimitre Novatchev |
Month |
Keywords