简体   繁体   English

xsl:call-template按名称存储在string中

[英]xsl:call-template by name stored in string

I have this xsl template: 我有这个xsl模板:

<xsl:template name="test">
I'm test
</xsl:template>

and I can call this template by calling 我可以通过调用来调用此模板

<xsl:call-template name="test"/>

QUESTION: How to call xsl template by name stored in variable? 问题:如何通过存储在变量中的名称调用xsl模板?

<xsl:variable name="var1" select="'test'"/>
<xsl:call-template name="$var1"/>

Instead of using xsl:call-template , try xsl:apply-templates . 不要使用xsl:call-template ,请尝试使用xsl:apply-templates

<xsl:template name="test" match="test">
I'm test
</xsl:template>

<xsl:variable name="var1"><test/></xsl:variable>

<xsl:apply-templates select="$var1/*"/>

But in XSLT 3.0 you can do this much more cleanly using higher-order functions; 但是在XSLT 3.0中,您可以使用高阶函数更干净地完成这项工作; functions become first-class values and can be bound to variables. 函数成为一等值,可以绑定到变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM