这在xsl中代表什么?匹配= “@ * |节点()”

时间:2013-06-20 09:41:42

标签: xml xslt-1.0

任何人都可以解释这在xsl中意味着什么吗?究竟每个表达代表什么

<xsl:template match="@*|node()">

1 个答案:

答案 0 :(得分:14)

@*匹配任何属性节点,node()匹配任何其他类型的节点(元素,文本节点,处理指令或注释)。因此,匹配@*|node()的模板将应用于任何未被更具体的模板使用的节点。

最常见的例子是身份模板

<xsl:template match="@*|node()">
  <xsl:copy><xsl:apply-templates select="@*|node()" /></xsl:copy>
</xsl:template>

将输入XML逐字复制到输出树。然后,您可以使用适用于特定节点的更具体的模板覆盖此模板,以对XML进行小的调整,例如,此样式表将创建与输入相同的输出XML,但所有foo元素都具有他们的名字改为bar

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="@*|node()">
    <xsl:copy><xsl:apply-templates select="@*|node()" /></xsl:copy>
  </xsl:template>

  <xsl:template match="foo">
    <bar><xsl:apply-templates select="@*|node()" /></bar>
  </xsl:template>
</xsl:stylesheet>