如何动态更改xsl:output方法属性值?

Mar*_*niz 1 xml xslt

我想使用相同的 xslt 并针对不同的输出(即 xml、html、xhtml 和文本)进行测试;当然我正在这样做:

<xsl:output method="xml" indent="yes"/>
Run Code Online (Sandbox Code Playgroud)

或者

<xsl:output method="html" indent="yes"/>
Run Code Online (Sandbox Code Playgroud)

但我想通过一个通知参数动态更改,如果我省略它,则默认为 xml。

我试过这个:

<xsl:param name="outputMethod" select="xml" />  
<xsl:output method="$outputMethod"indent="yes"/>
Run Code Online (Sandbox Code Playgroud)

没有成功,输出是:

 XTSE0020: Invalid value for serialization method: must be
  xml|html|xhtml|text|json|adaptive, or a QName in '{uri}local' form
Run Code Online (Sandbox Code Playgroud)

并尝试了这种更复杂的方式,我知道:

<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"/>
Run Code Online (Sandbox Code Playgroud)

也没有成功,输出是:

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
Run Code Online (Sandbox Code Playgroud)

那么,有更正吗?建议?

或者是否无法动态更改 xsl:output 方法?

TIA

Max*_*oro 5

使用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>
Run Code Online (Sandbox Code Playgroud)