views:

43

answers:

1

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"&gt;
<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="September" 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>
+1  A: 

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>
0xA3
I think that will do it! Didn't know you couldn't use variables or external params in the match expression. Thanks a ton!
Jeff
It's allowed in XSLT 2.0 though, so I'm not suprised if you've seen it being used somewhere.
Per T