简体   繁体   English

XPath参考

[英]XPath reference

I don't know the proper terminology for what I'm looking for, but what I am looking for is a complete reference the statements that can go between the double quotes, things like * , node() , @* , and all the ones listed here plus any others that exist. 我不知道我正在寻找什么的正确术语,但我正在寻找的是完整的参考双引号之间的语句,如*node()@*和所有这里列出的以及任何其他存在的。

<xsl:template match="*">

The answer I linked to provides some detail, but not enough. 我链接的答案提供了一些细节,但还不够。 For instance, that answer says "can be applied to any element" about the example I gave above, but what is considered an "element" in Xpath? 例如,关于我上面给出的示例,该答案说“可以应用于任何元素”,但在Xpath中被视为“元素”? What does node() include? node()包含什么? What statements include attributes? 哪些陈述包含属性? etc. 等等

I have searched the references here and here and I'm slowly making my way through this book, but I'm not seeing the info I want, which is basically a consolidated (and hopefully exhaustive) list of statements and what they mean. 我在这里这里搜索了参考文献,我正在慢慢地阅读本书,但我没有看到我想要的信息,这基本上是一个统一的(并且希望是详尽的)语句列表及其含义。 Does such a list exist and if so where is it? 这样的清单是否存在,如果存在,它在哪里? Free is nice but not necessary. 免费很好,但没有必要。

In XSLT, the match pattern accepts a subset of XPath expressions. 在XSLT中, match模式接受XPath表达式的子集。 So the set of expressions which can appear as the value of a match attribute is governed by two specs: the XPath specification itself, which defines the language of which match-patterns are a subset, and the XSLT specification, which defines the subset. 因此,可以作为match属性的值出现的表达式集由两个规范控制:XPath规范本身(定义匹配模式是其子集的语言)和XSLT规范(定义子集)。

If you are working with XSLT 1.0, the authoritative account is given by the XPath 1.0 specification and the XSLT 1.0 specification. 如果您使用的是XSLT 1.0,则权威帐户由XPath 1.0规范和XSLT 1.0规范提供。 It is in the nature of XPath that the language is infinite in size; XPath的本质是语言无限大; there cannot be an exhaustive list of legal patterns. 没有一份详尽的法律模式清单。 Instead, the set of legal patterns is defined by a context-free grammar given in the XSLT and XPath specs. 相反,这组合法模式是由XSLT和XPath规范中给出的无上下文语法定义的。

If you are working with XSLT 2.0, the relevant specs are XPath 2.0 (Second Edition) and XSLT 2.0 . 如果您正在使用XSLT 2.0,相关规范是XPath 2.0 (第二版)和XSLT 2.0 Again, the definition of legal match patterns uses a grammar defined partly in the XSLT spec and partly in the XPath spec. 同样,合法匹配模式的定义使用部分在XSLT规范中定义的语法,部分在XPath规范中定义。

You ask what is considered an "element" in Xpath? 你问Xpath中被认为是什么“元素”? What does node() include? node()包含什么? What statements include attributes? 哪些陈述包含属性? etc. 等等

Both versions of XPath define how to evaluate expressions against instances of the XPath data model; 两个版本的XPath都定义了如何根据XPath数据模型的实例计算表达式; it is the data model that specifies that all element nodes are nodes, but not all nodes are element nodes (and so on). 它是指定所有元素节点都是节点的数据模型,但并非所有节点都是元素节点(依此类推)。 The data model for XPath 1.0 is simpler and in general easier to understand, but its definition is rather informal and has what some readers regard as some problematic gaps and contradictions; XPath 1.0的数据模型更简单,通常更容易理解,但它的定义相当非正式,并且有些读者认为这是一些有问题的差距和矛盾; it is defined in section 5 of the XPath 1.0 specification . 在XPath 1.0规范的第5节中定义。 The XPath 2.0 data model is used not only by XPath and XSLT but also by XQuery; XPath 2.0数据模型不仅用于XPath和XSLT,还用于XQuery; it is defined in a spec called unsurprisingly XQuery 1.0 and XPath 2.0 Data Model (XDM) . 它是在一个名为XQuery 1.0和XPath 2.0数据模型(XDM)的规范中定义的。

A good book on XSLT will typically also provide a good account of the data model; 一本关于XSLT的好书通常也会提供数据模型的良好说明; depending on the style of the book, of course, it may be more or less exhaustive and be more or less careful about corner cases. 当然,取决于书的风格,它可能或多或少是详尽无遗的,并且对角落情况或多或少都要小心。 There are several good books, and I have heard people say good things about Doug Tidwell's book. 有几本好书,我听过人们对Doug Tidwell的书说好话。 But the one XSLT book I have found on every serious XSLT programmer's shelf is the one written by Michael Kay. 但是,我在每个严肃的XSLT程序员的架子上找到的一本XSLT书都是Michael Kay写的。 (Actually, most serious XSLT programmers I know own two: the XSLT 1.0 version and the XSLT 2.0 version.) (实际上,我认识的最严重的XSLT程序员有两个:XSLT 1.0版本和XSLT 2.0版本。)

From the wording of your question, it sounds as if you may also want to read some systematic introductions to XML itself. 根据您的问题的措辞,听起来好像您可能还想阅读一些有关XML本身的系统介绍。

I'm reminded a little of the manager who asks you for plans to rid the world of cancer, and insists they must be presented tomorrow on a single sheet of A4 paper. 我想起了一位经理,他要求你提出让世界摆脱癌症的计划,并坚持要求他们明天必须出示在一张A4纸上。 You've discovered that you need more technical detail than the simpler "single-sheet" references provide, but you still value their simplicity: you are asking for completeness and brevity at the same time, and that's a tough order. 您已经发现需要比简单的“单页”参考文献更多的技术细节,但您仍然重视它们的简单性:您同时要求完整性和简洁性,这是一个艰难的订单。

I think you're actually well on the way to answering your own question. 我认为你在回答自己的问题的过程中确实很好。 You're discovered that you need a better understanding of the data model, as this underpins the semantics of all the XPath expressions and XSLT patterns that you need to write. 您发现需要更好地理解数据模型,因为这会支持您需要编写的所有XPath表达式和XSLT模式的语义。 As Michael Sperberg-McQueen points out, there's an admirably concise but lamentably informal description of the model in the XPath 1.0 specification, and an admirably detailed but lamentably verbose description in the XDM spec linked from XSLT 2.0 and XQuery 1.0. 正如Michael Sperberg-McQueen所指出的那样,在XPath 1.0规范中对模型有一个令人钦佩的简洁但可悲的非正式描述,以及从XSLT 2.0和XQuery 1.0链接的XDM规范中令人钦佩的详细但令人遗憾的冗长描述。 Equally, you've also discovered that any short reference to the XPath (or pattern) grammar and semantics is going to be incomplete, but any longer description is going to take time to absorb. 同样,您还发现任何对XPath(或模式)语法和语义的简短引用都将是不完整的,但是任何更长的描述都需要时间来吸收。 So you know the choices you have to make! 所以你知道你必须做出的选择!

An element is an XML structure like <Something> , an attribute looks like Something="value" and both can be referred as node . 元素是像<Something>这样的XML结构, 属性看起来像Something="value" ,两者都可以称为节点

I think a good reference is XPath specification itself. 我认为一个很好的参考是XPath规范本身。 Takes a while to read it all and some more to understand it, but it's a nice place to pickup some terminology to formulate more specific questions. 需要一段时间来阅读所有内容以及更多内容才能理解它,但这是一个很好的地方,可以提取一些术语来制定更具体的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM