【问题标题】:difference between <xsl:apply-templates select="@*|node()" /> ,<xsl:apply-templates select="@*|*" /><xsl:apply-templates select="@*|node()" /> ,<xsl:apply-templates select="@*|*" /> 的区别
【发布时间】:2016-02-15 08:44:37
【问题描述】:

我是 XSLT 的新手,当我在项目中看到几个现有的 xslt 文件时,我看到了以下 sn-ps,

  1. &lt;xsl:apply-templates select="@*|node()" /&gt;
  2. &lt;xsl:apply-templates select="@*|*" /&gt;

有人可以解释一下上述2之间有什么区别吗? 谢谢,小猫

【问题讨论】:

    标签: xslt


    【解决方案1】:

    node() 匹配元素、文本节点、处理指令和 cmets。所以node()*|text()|processing-instruction()|comment()是一样的

    * 只匹配元素

    @* 匹配属性

    所以,如果你有以下 XML

    <Root Attribute="1">
      Text Node
      <Element>Text</Element>
    </Root>
    

    然后,假设您位于Root 节点上,如果您选择了&lt;xsl:apply-templates select="@*|node()" /&gt;,那么它将选择AttributeText NodeElement。但是&lt;xsl:apply-templates select="@*|*" /&gt; 只会选择AttributeElement

    【讨论】:

      猜你喜欢
      • 2013-04-15
      • 1970-01-01
      • 2019-04-03
      • 1970-01-01
      • 2016-02-15
      • 1970-01-01
      • 1970-01-01
      • 2021-03-15
      • 2016-08-28
      相关资源
      最近更新 更多