Reputation: 79
So I'm trying to create a variable and then later on use this in my template.
This is the code I have now:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="items">
<xsl:call-template name="item" />
</xsl:template>
<xsl:template name="item">
<xsl:for-each select="item">
<xsl:variable name="currentItemTheme">
test variable
</xsl:variable>
<xsl:if test="title = name">
Showvariable: {$currentItemTheme} <br/>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I have no idea why it doesn't work. My file does output the "Showvariable: ", but it just doesn't show the test values. So the for-each loops and template aren't the problem.
Is there something I'm missing? Does someone know how I get this to work?
Upvotes: 2
Views: 26
Reputation: 167716
I think you want <xsl:value-of select="$currentItemTheme"/>
instead of {$currentItemTheme}
, unless you are mixing the XSLT code with some other language that provides the {$currentItemTheme}
syntax.
<xsl:copy-of select="$currentItemTheme"/>
is another option if you build nodes in your variable and want to output them instead of just the string value as a text node.
Upvotes: 3