Can anyone explain what this means in xsl? Exactly what does each expression stands for
任何人都可以解释这在xsl中意味着什么?每个表达式究竟代表什么
<xsl:template match="@*|node()">
1 个解决方案
#1
10
@*
matches any attribute node, and node()
matches any other kind of node (element, text node, processing instruction or comment). So a template matching @*|node()
will apply to any node that is not consumed by a more specific template.
@ *匹配任何属性节点,node()匹配任何其他类型的节点(元素,文本节点,处理指令或注释)。因此,匹配@ * | node()的模板将应用于未由更具体的模板使用的任何节点。
The most common example of this is the identity template
最常见的例子是身份模板
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()" /></xsl:copy>
</xsl:template>
which copies the input XML to the output tree verbatim. You can then override this template with more specific ones that apply to particular nodes to make small tweaks to the XML, for example, this stylesheet would create an output XML that is identical to the input except that all foo
elements have had their names changed to bar
:
它将输入XML逐字复制到输出树。然后,您可以使用适用于特定节点的更具体的模板覆盖此模板,以对XML进行小的调整,例如,此样式表将创建与输入相同的输出XML,但所有foo元素的名称已更改为酒吧:
<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>
#1
10
@*
matches any attribute node, and node()
matches any other kind of node (element, text node, processing instruction or comment). So a template matching @*|node()
will apply to any node that is not consumed by a more specific template.
@ *匹配任何属性节点,node()匹配任何其他类型的节点(元素,文本节点,处理指令或注释)。因此,匹配@ * | node()的模板将应用于未由更具体的模板使用的任何节点。
The most common example of this is the identity template
最常见的例子是身份模板
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()" /></xsl:copy>
</xsl:template>
which copies the input XML to the output tree verbatim. You can then override this template with more specific ones that apply to particular nodes to make small tweaks to the XML, for example, this stylesheet would create an output XML that is identical to the input except that all foo
elements have had their names changed to bar
:
它将输入XML逐字复制到输出树。然后,您可以使用适用于特定节点的更具体的模板覆盖此模板,以对XML进行小的调整,例如,此样式表将创建与输入相同的输出XML,但所有foo元素的名称已更改为酒吧:
<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>