Subject: RE: [xsl] XPath and recursion From: "Michael Kay" <mhk@xxxxxxxxx> Date: Thu, 23 Oct 2003 08:39:13 +0100 |
This looks rather simple, or have I missed something? <xsl:template match="node/node"> <xsl:variable name="level" select="count(ancestor::node)"/> <xsl:value-of select="concat( 'aux', $level+1, ' = insFld(aux', $level, ', gfld(, $quot, @value1, $quot, '))
'"/> <xsl:apply-templates/> </xsl:template> <xsl:template match="document/node"> <xsl:variable name="level" select="count(ancestor::node)"/> <xsl:value-of select="concat( 'aux', $level+1, ' = insFld(foldersTree', ', gfld(, $quot, @value1, $quot, '))
'"/> <xsl:apply-templates/> </xsl:template> <xsl:variable name="quot">"</xsl:variable> <xsl:output method="text"/> Michael Kay > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Jonny Pony > Sent: 23 October 2003 07:32 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] XPath and recursion > > > Hi, > > I'm pretty new to XPath and I want to achive the following. > > I've got an xml-file, something like this: > > <?xml version="1.0" encoding="UTF-8"?> > <document> > <node value1="DB Objects"> > <node value1="Andreas"> > <node value1="Peter"> > <node value1="Kempten"/> > <node value1="Ulperting"/> > </node> > <node value1="Muahhh"/> > <node value1="Christoph"> > <node value1="Ulperting"/> > <node value1="FrankyBoy"> > <node value1="Munich"/> > </node> > </node> > </node> > <node value1="Christoph"> > <node value1="Munich"/> > <node value1="FrankyBoy"> > <node value1="Kempten"/> > </node> > </node> > <node value1="Frank"/> > </node> > <node value1="Tables"> > <node value1="Andreas"> > <node value1="Peter"> > <node value1="Munich"/> > <node value1="Ulperting"/> > </node> > </node> > ... > </node> > </document> > > And I want to get an output like this after the xsl transformation: > > aux1 = insFld(foldersTree, gFld("DB-Objects")) > aux2 = insFld(aux1, gFld("Andreas",)) > aux3 = insFld(aux2, gFld("Peter")) > aux4 = insFld(aux3, gFld("Kempten")) > aux4 = insFld(aux3, gFld("Ulperting")) > aux3 = insFld(aux2, gFld("Muahhh")) > aux3 = insFld(aux2, gFld("Christoph")) > aux4 = insFld(aux3, gFld("FrankyBoy")) > aux5 = insFld(aux4, gFld("Munich")) > aux5 = insFld(aux4, gFld("FrankyBoy")) > aux6 = insFld(aux5, > gFld("Kempten")) > aux6 = insFld(aux5, > gFld("Kempten")) > aux2 = insFld(aux1, gFld("Christoph")) > aux2 = insFld(aux1, gFld("Frank")) > aux3 = insFld(aux2, gFld("Peter")) > aux4 = insFld(aux3, gFld("Ulperting")) > aux3 = insFld(aux2, gFld("Muahhh")) > aux3 = insFld(aux2, gFld("Christoph")) > aux4 = insFld(aux3, gFld("Ulperting")) > aux4 = insFld(aux3, gFld("FrankyBoy")) > aux5 = insFld(aux4, gFld("Munich")) > aux1 = insFld(foldersTree, gFld("Tables")) > aux2 = insFld(aux1, gFld("Andreas",)) > aux3 = insFld(aux2, gFld("Peter")) > aux4 = insFld(aux3, gFld("Kempten")) > aux3 = insFld(aux2, gFld("Christoph")) > aux4 = insFld(aux3, gFld("Munich")) > aux4 = insFld(aux3, gFld("Ulperting")) > > The idea behind that: > if /document has at least a child, write: > aux1 = insFld(foldersTreeview, gFld( "<xsl:value-of > select="@value1"/>")); > if the child got at least another child,write: > aux2 = insFld(aux1, gFld("<xsl:value-of > select="@value1"/>"); if the child of the child got at least > another child,write: > aux3 = insFld(aux2, gFld("<xsl:value-of > select="@value1"/>"); and so on.... > > I tried to solve this problem for a long time now, but > falways failed. Also > the numbering of "aux", the deeper i get into the node-tree, > is impossibly > for me. Have no clue how I would do that. > > > Thanks > Jonny > > _________________________________________________________________ > 5 neue Buddies = 50 FreeSMS. http://messenger-mania.msn.de > MSN Messenger > empfehlen und kräftig abräumen! > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] XPath and recursion, Jonny Pony | Thread | Re: [xsl] XPath and recursion, M. David Peterson |
[xsl] XPath and recursion, Jonny Pony | Date | Re: [xsl] XPath and recursion, Dimitre Novatchev |
Month |