如何访问 xsl:output 属性中的 xsl:param?

2023-12-10

我想允许转换器在样式表中设置一个参数来指定需要多少个缩进空间。我已经尝试了 @Dimitre Novatev 在答案中的所有建议here无济于事。

<xsl:param name="indent" select="0"/><!-- default indent is 0, but transformer could specify a different value -->
<xsl:output indent="yes" method="xml" omit-xml-declaration="yes" xalan:indent-amount="{$indent}"/> <!-- This does not work -->

我如何分配的值indent参数到xalan:indent-amount属性?


Xalan 似乎不支持属性值模板xalan:indent-amount属性。

我收到一条警告消息,指出 XSLT 1.0 中的 xsl:output 不支持属性值模板。显然,它们在 1.1 中受支持(不应使用,因为它已被 W3C 放弃),但 Xalan 似乎并未解析 AVT 中该特定属性的参数值。

当我尝试在 AVT 中使用参数值时,它返回错误:

E For input string "{$indent}"

一种可能的解决方法是使用实​​体并生成 DTD。让您的 XSLT 引用 DTD,而不是将缩进值作为参数传递。生成具有所需缩进值的 DTD 文件,然后调用 XSLT。

例如,创建一个如下所示的 DTD 文件(假设名为“indent.dtd”):

<!ENTITY indent "10" >

然后像这样在 XSLT 中引用 DTD(假设 indent.dtd 位于同一文件夹中,或者您可以调整路径):

<!DOCTYPE xsl:stylesheet SYSTEM "indent.dtd">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output indent="yes" method="xml" omit-xml-declaration="yes" 
               xalan:indent-amount="&indent;"/> 

</xsl:stylesheet>

另一种解决方法是生成一个具有所需值的 XSLTxalan:indent-amount首先,然后使用新生成的 XSLT 转换 XML。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何访问 xsl:output 属性中的 xsl:param? 的相关文章

随机推荐