XPath expressions (abbreviations and detailed descriptions)

Source: Internet
Author: User
Tags xslt
XPath is the expression syntax used by XSLT (Extensible Stylesheet Language for transformations, extensible style sheet language) to locate the position of elements in the XSLT document.

XPath positioning addressing has two types of syntax: An unabbreviated syntax and an abbreviated syntax. The unabbreviated syntax can clearly express the meaning of the positioning path, which is very helpful for learning and understanding some concepts at the beginning. Most developers use the abbreviated syntax to make development more efficient.

A positioning step consists of three parts: axis, node test, and predicate. The axis and node test are separated by a double colon (: :). They are all required. The predicate is optional. If a predicate is specified, it must be tested immediately after the node and included in brackets. Each positioning step in the path is separated by a slash. If the node search starts at the root node (absolute path), the first positioning step also starts with a slash.

Below are some common XPath syntaxes:

1. Meaning: select the document root
Unabbreviated Syntax :/
Abbreviated Syntax :/

2. Meaning: select all the Para element nodes in the Child Nodes of the current node.
Unabbreviated Syntax: Child: Para
Abbreviated Syntax: Para

3. Meaning: select all the Para element nodes of the child nodes in the root node (note the difference from the previous example)
Unabbreviated Syntax:/child: Para
Abbreviated Syntax:/para

4. Meaning: select all the Para element nodes in the descendant nodes of the current node.
Unabbreviated Syntax: descendant: Para
Abbreviated Syntax:. // para

5. Meaning: select all the Para element nodes in the descendant nodes of the root node (note the difference from the previous example)
Unabbreviated Syntax:/descendant: Para
Abbreviated Syntax: // para

6. Meaning: select all Id attributes of the current node
Unabbreviated Syntax: attribute: ID
Abbreviated Syntax: @ para

7. Meaning: select all attributes of the current node
Unabbreviated Syntax: attribute ::*
Abbreviated Syntax :@*

8. Meaning: select the fifth chapter element node in the subnode of the current node.
Unabbreviated Syntax: Child: chapter [position () = 5]
Abbreviation Syntax: chapter [5]

9. Meaning: select all Chapter element nodes whose ID is this-one in the subnode of the current node.
Unabbreviated Syntax: Child: chapter [attribute: Id = "this-one"]
Abbreviated Syntax: chapter [@ ID = "this-one"]

10. Meaning: select all Chapter element nodes whose property value is not y.
Unabbreviated Syntax: Child: chapter [not (attribute: Include = "y")]
Abbreviated Syntax: chapter [@ include = "y"]

11. Meaning: select all text nodes in the descendant of the root node (that is, all text nodes in the document)
Unabbreviated Syntax:/descendant: Text ()
Abbreviation Syntax: // text ()

12. Meaning: select all the part nodes whose num attribute value is 1 and draft attribute value is Y in the subnode of the current node.
Unabbreviated Syntax: Child: part [attribute: num = "1"] [attribute: Draft = "Y"]
Abbreviated Syntax: chapter [@ num = "1"] [@ draft = "Y"]

13. Meaning: select the parent node of the current node. If the parent node has the include attribute and the value is y
Unabbreviated Syntax: parent: node () [attribute: Include = "y"]
Abbreviated Syntax: .. [@ include = "y"]

14. meaning: select all Chapter element nodes with both the ID and include attributes (no matter what the attribute value is)
unabbreviated Syntax:/descendant: chapter [attribute :: ID and attribute: Include]
abbreviated Syntax: // Chapter [@ ID and @ include]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.