如何在 xsl:output 的属性中访问 xsl:param? [英] How to access xsl:param in an attribute of xsl:output?

查看:37
本文介绍了如何在 xsl:output 的属性中访问 xsl:param?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让转换器在我的样式表中设置一个参数来指定需要多少个缩进空格.我已经尝试了@Dimitre Novatchev 在此处的答案中提出的所有建议,但均无济于事.

I want to allow the transformer to set a param in my stylesheet to specify how many spaces of indentation are desired. I have tried all of the suggestions by @Dimitre Novatchev in the answer here to no avail.

<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 属性?

How do I assign the value of the indent param to the xalan:indent-amount attribute?

推荐答案

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

It does not appear that Xalan supports attribute value templates for the value of the xalan:indent-amount attribute.

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

I get a warning message that attribute value templates are not supported in xsl:output in XSLT 1.0. Apparently, they are supported in 1.1 (which should not be used, as it was abandoned by the W3C), but Xalan does not appear to resolve the parameter value in the AVT in that particular attribute.

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

When I attempt to use the parameter value in an AVT, it returns the error:

E For input string "{$indent}"

<小时>

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


One possible workaround would be to use entities and generate a DTD. Rather than pass in the indent value as a param, have your XSLT reference a DTD. Generate the DTD file with the indent value that you need and then invoke the XSLT.

例如,创建一个这样的 DTD 文件(假设名为indent.dtd"):

For example, create a DTD file like this (assume named "indent.dtd"):

<!ENTITY indent "10" >

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

And then reference the DTD in your XSLT like this (assume that indent.dtd is located in the same folder, or you could adjust the path):

<!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>

<小时>

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


Another workaround would be to generate an XSLT with the desired value for the xalan:indent-amount first, and then transform your XML with the newly generated XSLT.

这篇关于如何在 xsl:output 的属性中访问 xsl:param?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆