Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My XSLT Variable doesn't load in template

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

Is there something I’m missing? Does someone know how I get this to work?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading