[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Searching for the longest path in a tree
Hi Norman, Please try this XSL.. I have modularized the stylesheet by having a named template.. I am also assuming you are interested in element nodes only.. <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" /> <xsl:template match="/"> <xsl:call-template name="max-depth"> <xsl:with-param name="node-set" select="//*" /> </xsl:call-template> </xsl:template> <xsl:template name="max-depth"> <xsl:param name="node-set" /> <xsl:for-each select="$node-set"> <xsl:sort select="count(ancestor::*)" order="descending" data-type="number" /> <xsl:if test="position() = 1"> <xsl:value-of select="count(ancestor::*)" /> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet> Regards, Mukul --- Norman Rosner <normanrosner@xxxxxx> wrote: > Hi everyone, > > i'm sure that theres help in the archive but i > didn't find something > that i can understand :) > > Here's my XML-Document: > > <?xml version="1.0" encoding="UTF-8"?> > > <corpus> > <phrase id="syntax_7"> <!-- Diskurs-Baum --> > > <phrase id="syntax_5"> <!-- Satz 1 --> > <phrase id="syntax_1" cat="NP" func="PD" > case="NOM"> > <tok id="tok_1" lemma="dies" > pos="PDS">Dies</tok> > <tok id="tok_2" lemma="sein" > pos="VAFIN">ist</tok> > </phrase> > > <phrase id="syntax_2" cat="NP" func="SB" > case="NOM"> > <tok id="tok_3" lemma="eine" pos="ART">ein</tok> > <tok id="tok_4" lemma="Beispielsatz" > pos="NN">Beispielsatz</tok> > </phrase> > > <tok id="tok_5" pos="$.">.</tok> > </phrase> > > <phrase id="syntax_5"> <!-- Satz 2 --> > <tok id="tok_6" lemma="und" pos="KON">Und</tok> > <tok id="tok_7" lemma="hier" pos="ADV">hier</tok> > <tok id="tok_8" lemma="folgen" > pos="VVFIN">folgt</tok> > > <phrase id="syntax_3" cat="NP" func="IOBJ" > case="DAT"> > <tok id="tok_9" lemma="er" pos="PPER">ihm</tok> > </phrase> > > <tok id="tok_10" lemma="zum Beispiel" > pos="ADV">z.B.</tok> > <tok id="tok_11" lemma="noch" > pos="ADV">noch</tok> > > <phrase id="syntax_4" cat="NP" func="SB" > case="NOM"> > <tok id="tok_12" lemma="eine" > pos="ART">ein</tok> > <tok id="tok_13" lemma="weiter" > pos="ADJA">weiterer</tok> > <tok id="tok_14" lemma="Beispielsatz" > pos="NN">Beispielsatz</tok> > </phrase> > > <tok id="tok_15" pos="$.">.</tok> > </phrase> > </phrase> > </corpus> > > > > and here's my XSL-File that i would like to apply to > the above > XML-Document. > > The problem i have according to the xsl-file is that > i want to have the > maximal depth of the tree. In the example XML it is > 4 i think. > > Is there any simple Opportunity to find it out? I > need ir because i > want to transform the tree into a svg. > > Thanks a lot > > Norman > > __________________________________ Yahoo! Messenger Show us what our next emoticon should look like. Join the fun. http://www.advision.webevents.yahoo.com/emoticontest
|
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
|