我正在尝试使用 org.apache.xalan.xslt.Process 类通过 java/xalan (2.7.1) 转换我的 xml
我收到“额外非法 token ”,但不确定解决方法
我基本上想将参数传递给模板,然后使用该参数作为 <xsl:when test="$textAlign eq 'center'">
的属性
如果我通过了'center'
param 到 TableCell 模板中,我想创建一个文本居中的表格单元格,当然,'left'
将使内容左对齐。
错误消息提示 'center'
中心周围的引号使问题变得复杂,看起来应该没问题。
这里有一些片段(示例 xml 和 xsl)
<ingredients>
<ingredient>
<quantity>1 1/2</quantity>
<foodstuff>flour</foodstuff>
</ingredient>
</ingredients>
这是一个示例 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>
也许还有另一种方法可以做到这一点?我认为这很简单,但我想我只是对 xsl 不够熟悉
我的 xsl 引擎使用 xalan 2.7.1
org.apache.xalan.xslt.Process -IN test.xml -XSL test.xsl -OUT out.html
谢谢大家
最佳答案
eq
是 XPath 和 XSLT 2.0 中引入的运算符,您使用的 Xalan 仅支持 XPath 和 XSLT 1.0,因此请使用 =
运算符。
或者从 Xalan 迁移到 Saxon 9 ( http://saxon.sourceforge.net/ ),该处理器支持 XSLT 2.0。
关于java - 通过 xalan/java 通过 xsl/xslt 转换我的 xml 时出现 xslt 错误 : Extra illegal tokens: 'eq' , '' center'',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8537711/