ubiquibacon
ubiquibacon

Reputation: 10667

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.

<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? What does node() include? 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.

Upvotes: 3

Views: 376

Answers (3)

Michael Kay
Michael Kay

Reputation: 163458

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. 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. 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. 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. So you know the choices you have to make!

Upvotes: 2

Rubens Farias
Rubens Farias

Reputation: 57966

An element is an XML structure like <Something>, an attribute looks like Something="value" and both can be referred as node.

I think a good reference is XPath specification itself. 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.

Upvotes: 0

C. M. Sperberg-McQueen
C. M. Sperberg-McQueen

Reputation: 25034

In XSLT, the match pattern accepts a subset of XPath expressions. 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.

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. It is in the nature of XPath that the language is infinite in size; 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.

If you are working with XSLT 2.0, the relevant specs are XPath 2.0 (Second Edition) and 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.

You ask what is considered an "element" in Xpath? What does node() include? What statements include attributes? etc.

Both versions of XPath define how to evaluate expressions against instances of the XPath data model; 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; it is defined in section 5 of the XPath 1.0 specification. The XPath 2.0 data model is used not only by XPath and XSLT but also by XQuery; it is defined in a spec called unsurprisingly XQuery 1.0 and XPath 2.0 Data Model (XDM).

A good book on XSLT will typically also provide a good account of the data model; 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. But the one XSLT book I have found on every serious XSLT programmer's shelf is the one written by Michael Kay. (Actually, most serious XSLT programmers I know own two: the XSLT 1.0 version and the XSLT 2.0 version.)

From the wording of your question, it sounds as if you may also want to read some systematic introductions to XML itself.

Upvotes: 4

Related Questions