【问题标题】:can an xslt template carry both name and match attributes?xslt 模板可以同时带有名称和匹配属性吗?
【发布时间】:2011-06-25 13:54:59
【问题描述】:

以下 (a) 是否允许 (b) 有用

<xsl:template match="foo" name="bar"> 
</xsl:template>

(这意味着模板可以从递归模板处理或直接从&lt;xsl:call-template name="bar"/&gt;触发

【问题讨论】:

    标签: xslt


    【解决方案1】:

    简单地说,是的。我经常命名身份模板并使用&lt;xsl:call-template name="identity" /&gt; 直接调用它。

    它是一种继承形式的有用工具;您可以定义一个模板来匹配一个节点,另一个处理该节点的派生节点,然后调用更通用的模板。

    例如:

    <xsl:template match="animal" name="animal">
      <!-- handle any animal related stuff here -->
    </xsl:template>
    
    <xsl:template match="dog">
      <xsl:call-template name="animal" />
      <!-- handle any dog specific stuff here -->
    </xsl:template>
    

    【讨论】:

      【解决方案2】:

      如果一个 xsl:template 元素有一个 name 属性,它可能但不需要也有一个 match 属性。 来自W3C XSLT specification

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-29
        • 2013-02-13
        • 2011-11-08
        • 2012-03-13
        • 2018-04-06
        相关资源
        最近更新 更多