Using param in XSLT patterns
I am setting a xslt param with PHP, and then calling the transform. I want to use the param value in an XPath expression to grab the proper nodes, but this doesn't seem to be working. I am guess it's possible, I think I am just missing the syntax. Here what I have...
PHP:
$xslt->setParameter('','month','September');
XSL:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<!-- Heres my param from the PHP -->
<xsl:param name="month" />
<!-- Here where I want it for grab the month node with the attribute name="Sept开发者_开发技巧ember" but it doesn't work, gives me a compilation error -->
<xsl:template match="/root/year/month[@name = $month]">
<p>
<xsl:value-of select="$month" />
</p>
</xsl:template>
You get an error because it is not allowed to use variables (or external parameters) within the match
expression of a template.
You can use the following workaround:
<xsl:template match="/root/year/month">
<xsl:if test="@name = $month">
<p>
<xsl:value-of select="$month" />
</p>
</xsl:if>
</xsl:template>
精彩评论