Given
An XSLT stylesheet with a global variable:
<xsl:variable name="lang" select="/response/str[@name='lang']"/>
Question
Where from comes the limitation that using variables in predicates is incorrect in the xsl:template
matching pattern, but is acceptable in xsl:apply-templates
selecting pattern?
<!-- throws compilation error, at least in libxslt -->
<xsl:template match="list[@name='item_list'][$lang]"/>
<!-- works as expected -->
<xsl:template match="list[@name='item_list'][/response/str[@name='lang']]"/>
<!-- works as expected -->
<xsl:template match="response">
<xsl:apply-templates select="list[@name='item_list'][$lang]">
</xsl:template>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…