这在 xsl 中代表什么?匹配=“@*|节点()"; [英] What this stands for in xsl? match="@*|node()"

查看:26
本文介绍了这在 xsl 中代表什么?匹配=“@*|节点()";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释这在 xsl 中的含义?每个表达式到底代表什么

Can anyone explain what this means in xsl? Exactly what does each expression stands for

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

推荐答案

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

@* 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.

最常见的例子是身份模板

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

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

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:

<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>

这篇关于这在 xsl 中代表什么?匹配=“@*|节点()";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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