Subject: [xsl] generalisation of template From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx> Date: Thu, 17 Jan 2002 10:32:32 -0000 |
Hi all, I think Ive already asked this one but it didnt get any takers... maybe this time :) I have this template (c/o Ken) that traverses some nested XML and calls row_even or row_odd. The problem is that it uses the actual element names (qnames, right?) to recursively make its way through the tree. This is fine but a neater (and more future proof) solution would be a general template that could be applied to all 'nesting depths'. So, can this be done without using 'mplx' and using something like 'child[position()=last()][child has child nodes(!)]' ?? Can you even call templates in this way? The template looks like: <xsl:template match="mpl0|mpl1|mpl2|mpl3|mpl4"> <xsl:param name="last" select="0"/> <xsl:choose> <xsl:when test="( $last + position() ) mod 2 = 1"> <xsl:call-template name="row_even"/> </xsl:when> <xsl:otherwise> <xsl:call-template name="row_odd"/> </xsl:otherwise> </xsl:choose> <xsl:apply-templates select="mpl1|mpl2|mpl3|mpl4"> <xsl:with-param name="last" select="$last + last()"/> </xsl:apply-templates> </xsl:template> And the data structure looks like: (Basically, the next level of nesting is always the last element of the last node of the previous level) <mpl0> <n>Level 0</n> </mpl0> <mpl0> <n>Level 0</n> <mpl1> <n>Level 1</n> </mpl1> <mpl1> <n>Level 1</n> </mpl1> <mpl1> <n>Level 1</n> </mpl1> <mpl1> <n>Level 1</n> <mpl2> <n>Level 2</n> </mpl2> <mpl2> <n>Level 2</n> <mpl3> <n>Level 3</n> </mpl3> </mpl2> </mpl1> </mpl0> Output should be something like: Level 0 >Level 0 .Level 1 .Level 1 .Level 1 >.Level 1 ..Level 2 >..Level 2 ...Level 3 Also :) If the solution could include outputting a '>' or similar at the first element of each level (like a directory + or - ) that has child nodes (that have child nodes) then I would be extremely greatful Thanks andrew === XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] xhtml DOCTYPE problem, Steven Noels | Thread | Re: [xsl] generalisation of templat, Jeni Tennison |
[xsl] xhtml DOCTYPE problem, Houbrechts Ivo | Date | Re: [xsl] xhtml DOCTYPE problem, Joerg . Heinicke |
Month |