1

PHP で xslt パラメータを設定してから、変換を呼び出しています。XPath 式で param 値を使用して適切なノードを取得したいのですが、うまくいかないようです。可能だと思いますが、構文が欠けているだけだと思います。ここに私が持っているもの...

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 に答える