xslt 错误:通过 xalan/java 通过 xsl/xslt 转换我的 xml 时出现额外非法标记:'eq'、''center''

use*_*402 2 java xslt xalan

我正在尝试使用 org.apache.xalan.xslt.Process 类通过 java/xalan (2.7.1) 转换我的 xml

我收到“额外非法令牌”,但不确定解决方法

我基本上想将参数传递给模板,然后使用该参数作为模板的属性<xsl:when test="$textAlign eq 'center'">

如果我将'center'参数传递到 TableCell 模板中,我想创建一个文本居中的表格单元格,当然,'left'会使其内容左对齐。

错误消息抱怨'center'

中心周围的报价使它出错,看起来应该没问题。

这里有一些片段(示例 xml 和 xsl)

    <ingredients>         
          <ingredient>
                <quantity>1 1/2</quantity>
                <foodstuff>flour</foodstuff>
          </ingredient>
    </ingredients>
Run Code Online (Sandbox Code Playgroud)

这是一个示例 xsl

<xsl:output method="html"/>
<xsl:template match="ingredients">
      <xsl:apply-templates select="ingredient"/>
</xsl:template>
.
<xsl:template match="ingredient">
  <xsl:call-template name="TableCell">
        <xsl:with-param name="cellValue" select="quantity" />
        <xsl:with-param name="textAlign" select="'center'" />
  </xsl:call-template>
</xsl:template>
.
<xsl:template name="TableCell">
  <xsl:param name="cellValue" />
  <xsl:param name="textAlign" />
  <xsl:choose>
      <xsl:when test="$textAlign eq 'center'">
      <td align='center'>
        <xsl:value-of select="$cellValue"/>
      </td>
    </xsl:when>
  </xsl:choose>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

也许还有另一种方法可以做到这一点?我认为这很简单,但我想我只是对 xsl 不够熟悉

我的 xsl 引擎使用 xalan 2.7.1

org.apache.xalan.xslt.Process -IN test.xml -XSL test.xsl -OUT out.html
Run Code Online (Sandbox Code Playgroud)

感谢大家

Mar*_*nen 5

eq是 XPath 和 XSLT 2.0 中引入的运算符,您使用的 Xalan 仅支持 XPath 和 XSLT 1.0,因此请改用该=运算符。或者从 Xalan 迁移到 Saxon 9 ( http://saxon.sourceforge.net/ ),该处理器支持 XSLT 2.0。