Given this XML;
<root>
<foo x='1'/>
<foo x='3'/>
<foo x='7'/>
</root>
and this stylesheet;
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root">
<result>
<xsl:apply-templates select="foo"/>
</result>
</xsl:template>
<xsl:template match="foo[@x > 2]">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:transform>
I get the desired result;
<result>
<bar x="3"/>
<bar x="7"/>
</result>
But if the template match
for foo
is changed to use a variable $i
instead of a constant;
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="i" select="2"/>
<xsl:template match="root">
<result>
<xsl:apply-templates select="foo"/>
</result>
</xsl:template>
<xsl:template match="foo[@x > $i]">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:transform>
then I get this error;
XSLTProcessor::importStylesheet(): compilation error: Failed to compile predicate
Am I doing something wrong or can't variables be used in that way?
I have tried declaring the variable in other ways eg;
<xsl:variable name="i" select="2"/>
<xsl:variable name="i">2<xsl:variable>
but it always fails to compile the stylesheet.
I'm using the PHP XSL 1.0 processor libxslt;
PHP Version 5.3.2
libxslt Version 1.1.23