4. XPATH Syntax We have already mentioned above, XPath is the language used to help XSLT to find location information in the XML source document. During the actual use, XPath and XSLT are always mixed together. In the above chapter, we already have the syntax used to use XPath, just not clearly. But W3C divides them into two standards, so we also dismantled them into two chapters to explain. 4.XPath Syntax 4.1 Current Position 4.2 Addressing Operation 4.3 Operator 4.4 Function Function 4.1 Current location When we use the XSLT to process the XML source document, we use context to represent the node location that is currently being processed by the template. For example, the XSL: Template match = "/" statement indicates the root node of the document in the document. I don't know how to accurately translate the word word, which is similar to the pointer in the C language, indicating the location where the program is currently running. Understanding Context is very important to correctly handle the XSL template, when your XSL template outputs, the first thing you want, the first should be analyzed where CONTEXT is. Location Paths is used to set the CONTEXT node location you want to find. Similar to the DOS directory command. We look an example where Child :: people / descendant :: Person is xpath syntax, this expression is a location paths, code description to display The child elements of all People elements and child elements of all Person elements. Usually we will use simpler ways: We explain two representations of PATH: "/" and "//". "/" Is a node that represents the current document, similar to the DOS directory split. For example: / people represents the people elements under the root node; People / Person represents all the Peson sub-elements under the people. "//" means all nodes of the current document. Similar to view the entire directory. For example: // people indicate what the people have all in the document, whether it is what level; people // person represents all the Person elements under the people of the People, no matter how deep it. 4.2 Addressing Operation AXIS and PREDICATE is the syntax for positioning the Location Paths in the XPath syntax, and the specific usage list is as follows syntax table -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------- Expressive Description ------------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Self. Select the current node . Example:
Td> code means inserting the current node included in the current location, ----------- -------------------------------------------- parent .. Select the current The parent node of the node. -------------------------------------------------- ------ Attribute @ Select all properties of an element.
Example:
td> Select all properties of the Person element. -------------------- ---------------------------------- Child Select all child elements of the current node. -------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------ AXIS helps us choose all the nodes around the current node, and Predicate is used to locate the current node inside Elements. Representation is square bracket [] plus expression: [expression]. Specific examples are as follows: Person [position () = 2] This code indicates that the second "Person" element Person [starts-with (name, "b")] This code means looking for all names starting with "B" Person element. 4.3 Operator This section introduces the EXPRESSIONS, the list is as follows: -------------------------------- ------------------------ Operator Description ----------------------- -------------------------------- And, OR is the ordinary meaning and, or ------- ------------------------------------------------- = equal------------------------------------------------- -------! = Not equal to --------------------------------------- ----------------->,> = greater than, greater than or equal to ------------------------- ------------------------------ <, <= less than, less than or equal. Note: In the XSL file, p> Description: The purpose of the code is to display a few name attribute values in the Person element. Number () Features: Convert text in the value of the property to a value.