i've got the following xml as an example tree, and need to go through
the tree, level based!:
as an example: "all title elements with level 0" should give me the
element "title" with its childs commented as "element 1"
a 2nd example: "all title elements with level 1" should give me the
elements "title" with its childs commented as "element 2" and "element 3"
<tablehead>
<title> <!-- this is element 1 -->
<value>Saldo letzter Abschluss</value>
<cssclass>head</cssclass>
<colwidth>250</colwidth>
<visibility>visible</visibility>
<layout>fixed</layout>
<subtitles>
<title> <!-- this is element 2 -->
<value>Soll</value>
<cssclass>head</cssclass>
<colwidth>125</colwidth>
<sortorder>no</sortorder>
</title>
<title> <!-- this is element 3 -->
<value>Haben</value>
<cssclass>head</cssclass>
<colwidth>125</colwidth>
<sortorder>no</sortorder>
</title>
</subtitles>
</title>
</tablehead>
the following stylesheet do that (nearly) correct:
- call to template:
<xsl:call-template name="jumptolevel" >
<!-- specify the level -->
<xsl:with-param name="level" select="1" />
<!-- root titles -->
<xsl:with-param name="elements" select="/tablehead/title" />
</xsl:call-template>
- template itself:
<xsl:template name="jumptolevel">
<xsl:param name="i" select="0" />
<xsl:param name="level" select="0" />
<xsl:param name="elements" />
<xsl:choose>
<xsl:when test="$i < $level">
<xsl:call-template name="jumptolevel">
<xsl:with-param name="i" select="$i + 1" />
<xsl:with-param name="level" select="$level" />
<xsl:with-param name="elements"
select="$elements/subtitles/title" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$elements" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
the problem is, i need the result of the template "jumptolevel" as a
reference in the whole tree.
when i call the template as followed
<xsl:variable name="test">
<xsl:call-template name="jumptolevel" >
<!-- specify the level -->
<xsl:with-param name="level" select="1" />
<!-- root titles -->
<xsl:with-param name="elements" select="/tablehead/title" />
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="name($test/..)" />
i want to have "subtitles" displayed!
the result should give me also the parent nodes, how do i do that? or
what i did wrong?
thanks in advance (sorry, for my bad english, i'm swiss ;)
jimmy
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list