Hello All,
I have been experiencing some problems while trying to write a recursive template in XSL.
The formatting of my xml docs is as follows:
<nestedElement>
<tagName>tag</tagName>
<someTag>
<nestedElement>
<tagName>test</tagName>
<fieldAttribute>
<name>attribute1</name>
<var>temp</var>
</fieldAttribute>
<nestedElement>
<tagName>test1</tagName>
</nestedElement>
</nestedElement>
</nestedElement>
The template should loop through all the nestedElements, and the path in which the template is enterng should be stored in a variable. Still I can't get this to work for some weird reason. As far as I can get is this code.
<xsl:template name="nestedElement">
<xsl:param name="level" select="nestedElement" />
<xsl:for-each select="$level">
<xsl:variable name="nestedElementName" select="tagName" />
//this element is the output I want, together with the attributes that will be processed by the template underneath it
<xsl:element name="{$nestedElementName}">
<xsl:call-template name="fieldAttribute" />
<xsl:value-of select="testvalue" />
</xsl:element>
//I use this test for checking whether there is another element nested.. if so, recursion should occur.
<xsl:if test="nestedElement/tagName != """>
<xsl:variable name="nextlevel" />
//I tried to add this attriubte: select", "concat ($level, '/nestedElement')", but gives an error..
<xsl:call-template name="nestedElement">
<xsl:with-param name="level" />
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</xsl:template>
//this is the template for the fieldAttribute resolving
<xsl:template name="fieldAttribute">
<xsl:for-each select="fieldAttribute">
<xsl:variable name="tempname" select="name" />
<xsl:variable name="tempvalue" select="var" />
<xsl:attribute name="{$tempname}">
<xsl:copy-of select="$tempvalue" />
</xsl:attribute>
</xsl:for-each>
</xsl:template>
the variable nextlevel should store the current root level, e.g.
nestedElement/nestedElement, and increment each time the loop is entering a new child node.. each 'nestedElement' created with the variable nestedElementName should be nested in its appropriate level..
output should be like
<tag1>
<test attribute1='temp'>
<test1></test1>
</tagName>
</tagName>
as far as this code is, the template (with some changes) works for two levels
I would of have doen this by passing that variable as parameter with the new call.
Stills IE keeps giving errors about the undefined variable level..
or something about only one element being able to exist in the top node?
for a quick look at the whole thing.. it is online at
http://onuris.groept.be/ENG/eTech/a0...gister_kot.php
anyone has any ideas on this one? Took me a lot of time to sort it out
thanks in advance,
Jeroen