Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Why do I get a "variable not defined" error parsing this?
Here is my XML:
<order> <required id="Blur" qnty="3"/> <catalogue> <album id="Blur" price="12"/> <album id="Travis" price="13"/> </catalogue></order>
Here is my XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:variable name="r" select="//required/@id"/> <xsl:template match="album[@id=$r]"> We were looking for <xsl:value-of select="$r"/>and we found it! </xsl:template></xsl:stylesheet>
Thanks!
Hi Steve,
Unfortunately you can't use variables in a match pattern — the error message is a little off, though.
Though that's probably not your entire code, here's an alternate approach:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:variable name="r" select="//required/@id" /> <xsl:template match="/"> <xsl:apply-templates select="//album[@id = $r]" /> </xsl:template> <xsl:template match="album"> We were looking for <xsl:value-of select="@id"/>and we found it! </xsl:template> </xsl:stylesheet>
/Chriztian
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Template Match with a Variable
Why do I get a "variable not defined" error parsing this?
Here is my XML:
<order>
<required id="Blur" qnty="3"/>
<catalogue>
<album id="Blur" price="12"/>
<album id="Travis" price="13"/>
</catalogue>
</order>
Here is my XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="r" select="//required/@id"/>
<xsl:template match="album[@id=$r]">
We were looking for <xsl:value-of select="$r"/>and we found it!
</xsl:template>
</xsl:stylesheet>
Thanks!
Hi Steve,
Unfortunately you can't use variables in a match pattern — the error message is a little off, though.
Though that's probably not your entire code, here's an alternate approach:
/Chriztian
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.