1
votes

I know, that I can call xsl:apply-templates inside another template, when I specify the XPath-expression of that subtemplate.

In my xsl-file I got an

<xsl:template match="/">
    <xsl:apply-templates select="root/values" />
</xsl:template>

<xsl:template match="root/values>
    <xsl:value-of select="value/key" />
</xsl:template>

Now I want to do something with subnodes of root/values again in another context - how do I match this template in my main template?

<xsl:template match="root/values>
    <xsl:for-each select="value">
        <xsl:value-of select="key" />
    </xsl:for-each>
</xsl:template>
1
It would possible help if you showed a sample of the XML you are working with, and the output you are hoping to obtain. Thanks! - Tim C

1 Answers

2
votes

I think you want to use a mode:

<xsl:template match="/">
    <xsl:apply-templates select="root/values" />
    <xsl:apply-templates select="root/values" mode="m1" />
</xsl:template>

<xsl:template match="root/values>
    <xsl:value-of select="value/key" />
</xsl:template>

<xsl:template match="root/values" mode="m1">
    <xsl:for-each select="value">
        <xsl:value-of select="key" />
    </xsl:for-each>
</xsl:template>