Getting Started with XPath-xsl tutorials-3_xml basics

Source: Internet
Author: User
Tags first string unique id xml attribute xpath xsl xslt
What is XPath
XPath (extensible path) is the result of providing a common syntax and semantics for the shared functionality of XSL transformations [XSLT] and XPointer [XPointer]. The main purpose of XPath is to address XML document components. While supporting this primary purpose, it also provides a basic tool for string, digital, and Boolean operations. XPath uses concise, non-XML syntax to manipulate the abstract, logical structure of an XML document, rather than its surface syntax, within URIs and XML attribute values, and XPath's name originates from its use as a hierarchy of XML documents in a URL Navigate to a path flag.
In addition to being used for addressing, XPath is designed so that it has a natural subset that can be used to match (test whether a node matches a pattern), and XSLT describes the use of XPath in this regard.
XPath models an XML document into a node tree with different types of nodes, including element nodes, attribute nodes, and body nodes. XPath defines a method to compute the string value of a node for each class. Some types of nodes also have names. XPath fully supports XML namespaces [XML Names]. In this way, the name of the node is modeled as a pair consisting of a local part and possibly an empty namespace URI, which is called an extension.

Types returned by XPath
1: Node set (unordered, no duplicate node set)
2: Boolean (True or FALSE)
3: Number (a floating-point number)
4: String (Order of UCS characters)
Address path
The address path is a statement that XPath uses to locate, and the basic syntax is as follows:
/Select the root node of the XML document
/* Select all child nodes of the root node,
* Match any child nodes
/x selects all x elements of the root node
Book Select the book element in all descendant nodes of the root node
@id Select a child node that contains an id attribute
PARA[1] Select the first para child of the context node
vendor[@id = ' id1_2 ']/book Select all book elements that conform to the attribute id= ' id1_2 '
/BIB/VENDOR/BOOK[YEAR>2002] Selects all book elements that conform to the element year> ' 2002 '
Text () selects all the body nodes of the context node child
@name Select the Name property of the context node
@* selects all properties of the context node
*/para Select the context node of all the para grandchildren
/DOC/CHAPTER[5]/SECTION[2] Select the second section of Doc's fifth chapter
.//para select the Para element of the context node descendants
para[@type = "Warning"] all of the context nodes selected have attribute type and the value is warning para child
chapter[title= "Introduction" Select the chapter child of the context node if it has one or more title children and the string value is Introduction
employee[@secretary and @assistant] Select all Employee children with Secretary attributes and assistant attributes for the context node
Chpater[title] The context node selected has one or more chpater children of the title child
1:child is the default axis. For example, the address path Div/para is an abbreviation for child:iv/child::p Ara.
2: Attributes also have abbreviated form: attribute:: Can be abbreviated as @. For example, the address path para[@type = "Warning"] is the child::p the abbreviation for "Warning", which is warning children who have the type attribute and whose attribute value is para.
3://is a/descendant-or-self::node ()/abbreviation. For example,//para is the abbreviation for/descendant-or-self::node ()/child::p ara, so select all Para elements in the document (even if the para element is a document element, it will be chosen by the//para. Because the document element is the child of the root node; Div//para is Div/descendant-or-self::node ()/child::p ara abbreviation, so will select all para descendants of Div child
Core Function Library
Node aggregate functions
Last () returns a number equal to the context size from an expression evaluation context
The position () function returns a number that is equal to the context position in the evaluation context of an expression
The count (node-set) function returns the number of nodes in the parameter Node-set
ID (object) to select them by their unique ID
Local-name (Node-set?) Returns the local part of the extension of a node
Namespace-uri (Node-set?) Returns the namespace URI of the extension of the first node in the node collection of the document order parameter, except for the element and attribute node external function Namespace-uri the returned string will be empty
Name (Node-set?) Returns a string containing a QName that represents the extension of the first node in the collection of document order parameters, except for the element node and the attribute node, and the string returned by the name function will be the same as the string returned by the Local-name function
String functions
String (object?) function converts an object into a character.
Concat (String, string, string*) function returns the join of its arguments
Starts-with (String, String) if the first string argument begins with the second string argument, the Starts-with function returns True, otherwise, the false
Contains (string, string) if the first string parameter contains the second string argument, the contains function returns True, otherwise, returns a false
The Substring-before (string, String) function returns a substring of the first string argument before the first occurrence of the second argument, or an empty string if the first string parameter does not contain the second string parameter. For example, Substring-before ("1999/04/01", "/") returns 1999
The Substring-before (string, String) function returns a substring of the first string argument before the first occurrence of the second argument, or an empty string if the first string parameter does not contain the second string parameter. For example, Substring-before ("1999/04/01", "/") returns 1999
SUBSTRING (string, number, number?) function returns the first string parameter starting at the position specified by the second argument, and the length of the third argument as a substring. For example, substring ("12345", 2, 3) returns "234". If there is no third argument, the start of the position specified by the second argument is returned to the end. For example, substring ("12345", 2) returns "2345"
String-length (string?) Returns the number of characters in a string
Normalize-space (string?) function returns the normalized parameter string for whitespace, which clears the leading and trailing whitespace and replaces contiguous whitespace with a blank character.
The Translate (string, string, String) function returns the string of the first argument, where the character that appears in the second argument is replaced by a character that corresponds to the position in the third argument. For example, translate ("Bar", "ABC", "ABC") returns the string bar. If the character in the second argument has no characters in the corresponding position of the third argument (because the string in the second argument is longer than the third argument), then the character in the first argument will be removed. For example, translate ("--aaa--", "abc-", "abc") returns "AAA". If the character in the second argument appears more than once, then the first occurrence determines the replacement character. If the string in the third argument is longer than the string in the second argument, then the extra characters are ignored
Boolean functions
Boolean (object)
Not (Boolean)
True ()
False ()
Lang (String)
Number function
Number (object?) function parameters are converted to numbers according to the following
SUM (node-set) for each node in the set of parameter nodes, the SUM function returns the value of the node string converted to a number and
The floor (number) function returns the maximum of integers that are less than arguments (closest to positive infinity)
The ceiling (number) function returns the minimum of an integer that is not less than the argument (closest to the negative infinity)
The round (number) function returns the integer closest to the argument. If there are two such numbers, then return the one closest to the positive infinity. If the argument is Nan, then return nan. If the parameter is positive infinity, then return positive infinity. If the argument is negative infinity, then the negative infinity is returned. If the argument is positive zero, then the positive zero is returned. If the argument is negative 0, then negative 0 is returned. If the parameter is less than zero, but is greater than or equal to-0.5, then the negative 0 is returned.
Reference specification
XML http://www.w3.org/TR/1998/REC-xml-19980210
XML Nameshttp://www.w3.org/tr/rec-xml-names
XSLT http://www.w3.org/TR/xslt
Partial reference XML Path Language (XPath) version 1.0

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.