XSL xsl:template match="/"; [英] XSL xsl:template match="/"

查看:52
本文介绍了XSL xsl:template match="/";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在学习 XML 以及如何使用 XSL 文件.在 XSL 文件中,我发现了以下术语:

I am just learning XML and how to use XSL files. In an XSL file I found the following term:

xsl:template match="/"

这是什么意思?我可以用什么来代替 / ?我可以写 table 或任何其他 HTML 标签而不是 / 吗?

What does this stand for? And what could I use instead of the /? Could I write table or any other HTML tag instead of /?

推荐答案

指令的 match 属性的值必须是 匹配模式.

The value of the match attribute of the <xsl:template> instruction must be a match pattern.

匹配模式构成所有可能的 XPath 表达式集合的一个子集.第一个自然的限制是匹配模式必须选择一组节点.还有其他限制.特别是,位置步骤中不允许使用反向轴(但可以在谓词中指定).此外,在 XSLT 1.0 中不允许使用变量或参数引用,但在 XSLT 2.x 中使用这些是合法的.

Match patterns form a subset of the set of all possible XPath expressions. The first, natural, limitation is that a match pattern must select a set of nodes. There are also other limitations. In particular, reverse axes are not allowed in the location steps (but can be specified within the predicates). Also, no variable or parameter references are allowed in XSLT 1.0, but using these is legal in XSLT 2.x.

/ 表示 root 或文档节点.在 XPath 2.0(以及 XSLT 2.x)中,这也可以写成 document-node().

/ in XPath denotes the root or document node. In XPath 2.0 (and hence XSLT 2.x) this can also be written as document-node().

匹配模式可以包含 // 缩写.

A match pattern can contain the // abbreviation.

匹配模式示例:

<xsl:template match="table">

可以应用于任何名为 table 的元素.

can be applied on any element named table.

<xsl:template match="x/y">

可以应用于任何名为 y 的元素,其父元素是名为 x 的元素.

can be applied on any element named y whose parent is an element named x.

<xsl:template match="*">

可以应用于任何元素.

<xsl:template match="/*">

只能应用于 XML 文档的顶部元素.

can be applied only to the top element of an XML document.

<xsl:template match="@*">

可以应用于任何属性.

<xsl:template match="text()">

可以应用于任何文本节点.

can be applied to any text node.

<xsl:template match="comment()">

可以应用于任何评论节点.

can be applied to any comment node.

<xsl:template match="processing-instruction()">

可以应用于任何处理指令节点.

can be applied to any processing instruction node.

<xsl:template match="node()">

可以应用于任何节点:元素、文本、注释或处理指令.

can be applied to any node: element, text, comment or processing instructon.

这篇关于XSL xsl:template match="/";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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