如何动态更改 xsl:output 方法属性值? [英] How to dynamically change xsl:output method attribute value?
本文介绍了如何动态更改 xsl:output 方法属性值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用相同的 xslt 并针对不同的输出进行测试,即 xml、html、xhtml 和文本;我当然是这样做的:
I want to use the same xslt and test against different outputs, i e, xml, html, xhtml and text; of course I'm doing this:
<xsl:output method="xml" indent="yes"/>
或
<xsl:output method="html" indent="yes"/>
但我想通过通知参数动态更改,如果我省略它,则默认为 xml.
But I want to dynamically change through an informed parameter, defaulting to xml if I omite it.
我试过了:
<xsl:param name="outputMethod" select="xml" />
<xsl:output method="$outputMethod"indent="yes"/>
没有成功,输出为:
XTSE0020: Invalid value for serialization method: must be
xml|html|xhtml|text|json|adaptive, or a QName in '{uri}local' form
并尝试了这种更复杂的方法,我知道:
and tried this much more convoluted way, I know:
<xsl:variable name="thisDocument" select="document('')" />
<xsl:param name="outputMethod" select="xml" />
<xsl:variable name="myOutputMethod" select="$outputMethod"/>
<xsl:output method="$thisDocument/xsl:stylesheet/myOutputMethod" indent="yes"/>
也没有成功,输出是:
Static error at xsl:output on line 10 column 85 of CopyingNodes.xslt:
XTSE0020: Both the prefix {$thisDocument/xsl} and the local part
{stylesheet/myOutputMethod} are invalid
Errors were reported during stylesheet compilation
那么,有什么更正吗?建议?
So, any corrections? suggestions?
还是不能动态改变xsl:output方法?
Or is it impossible to dynamically change xsl:output method?
TIA
推荐答案
使用 xsl:result-document
:
<xsl:param name="method" select="'xml'"/>
<xsl:output indent="yes"/>
<xsl:template name="xsl:initial-template">
<xsl:result-document method="{$method}">
<!-- your code here -->
</xsl:result-document>
</xsl:template>
这篇关于如何动态更改 xsl:output 方法属性值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文