如何根据变量调用命名模板? [英] How to call named templates based on a variable?

查看:36
本文介绍了如何根据变量调用命名模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是否可能,但我想知道该怎么做...

I don't know if it's possible, but I'm wondering how to do it...

假设我们有以下 XSL:

Let's say we have the following XSL:

<xsl:template name="foo">
  Bla bla bla
</xsl:template>
...
<xsl:template name="bar">
  Bla bla bla
</xsl:template>
...
<xsl:template match="/">
  <xsl:if test="$templateName='foo'">
    <xsl:call-template name="foo"/>
  </xsl:if>
  <xsl:if test="$templateName='bar'">
    <xsl:call-template name="bar"/>
  </xsl:if>
</xsl:template>

是否可以将 XSL 更改为读取类似...

Is it possible to change the XSL to read something like...

<xsl:template match="/">
  <xsl:call-template name="$templateName"/>
</xsl:template>

推荐答案

不,这是不可能直接不可能的.调用约定是:

No, this is not possible not directly possible. The calling convention is:

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

其中 QName 定义为:>

QName ::= PrefixedName | UnprefixedName

PrefixedName   ::= Prefix ':' LocalPart
UnprefixedName ::= LocalPart

Prefix         ::= NCName
LocalPart      ::= NCName

基本上这归结为只有字符,没有表达式".正如其他答案所强调的那样, 实际上有一些方法可以做一些等效的事情,但是直接的方法/天真的方法是行不通的.

Basically this boils down to "characters only, no expressions". As the other answers highlight, there are in fact ways to do something equivalent, but the straightforward approach/naïve approach will not work.

这篇关于如何根据变量调用命名模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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