1

我正在用 PHP 设置一个 xslt 参数,然后调用转换。我想在 XPath 表达式中使用参数值来获取正确的节点,但这似乎不起作用。我想这是可能的,我想我只是缺少语法。这里我有什么...

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="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>
4

1 回答 1

1

您会收到错误,因为不允许在match模板表达式中使用变量(或外部参数)。

您可以使用以下解决方法:

<xsl:template match="/root/year/month">
    <xsl:if test="@name = $month">
      <p>
        <xsl:value-of select="$month" />
      </p>
    </xsl:if>
  </xsl:template>
于 2010-09-05T20:46:26.477 回答