This section describes the XSL style methods, which can be used for the select attributes of the XSL elements <XSL: For-each>, <XSL: value-of>, <XSL: Template>, and <XSL: filter the range of elements in the match attribute, <XSL: If>, and <XSL: When> of apply-templates> to provide greater flexibility.
Like DHTML (Dynamic HTML) and XML, these nodes are all objects, and these objects are hierarchical. Starting from the root node, a hierarchical tree structure is formed, this forms the Document Object Model Dom. The object attributes and methods are used to control access to XML nodes.
We do not plan to elaborate on the xml dom here, because it can be written into a large number of tutorials. Let's first discuss some common methods, in order to have a general understanding of DOM object methods.
Note: Starting from this issue, the complete source code is no longer provided for all examples. If you do not understand the source code, please carefully read the previous seven phases and start your hands.
I,End ()
Meaning: return the last element in the set.
Example: output the last resume
Assume that the XML file format is:
...... <Resume>... </Resume> ...... <Resume>... </Resume> ......
The content of the relevant XSL file is:
<XSL: For-each select = "resume [end ()]"> ...... </XSL: For-each>
Or
<XSL: templates match = "resume [end ()]"> ...... </XSL: templates>
Or
<XSL: Apply-template select = "resume [end ()]"> ...... </XSL: Apply-template>
II,Index ()
Meaning: return the position of the element in the set. The returned value is an integer. The first element returns 0.
Example: return the first three resumes
Resume [index () $ le $3]
Note: Index () is related to the parent element. See the following example:
<X>
<Y/>
<Y/>
</X>
<X>
<Y/>
<Y/>
</X>
Returns the first <Y> of all <x> values.
X/y [index () = 0]OrX/y [0]
III,Nodename ()
Meaning: the name of the returned element, that is, the tag name.
Example: select any element, if its name (that is, tag name) is equal to "name"
* [Nodename () = 'name']Or * [name]
IV,Number ()
Meaning: converts a value to a value. If it is not a value, null is returned. Required Parameter
Example: Resume of a person younger than 30 years old)
Resume [number (AGE) $ lt $30] or resume [age $ lt $30]
V,Nodetype ()
Description: Return node type. The result is a numerical value. The following is a list of returned values:
Node Type |
Node Type Value |
Character Form description of a node |
Element |
1 |
'Element' |
Element attribute |
2 |
'Attribute' |
Markup-delimited region of Text |
3 |
'Text' |
Processing Instruction |
7 |
'Processing_instruction' |
Comment |
8 |
'Comment' |
Document entity |
9 |
'Document' |
VI,Value ()
Meaning: return the value of an element or attribute.
Example: value () is the default method of an element or attribute.
Name! Value () = "name" and name = "name"
@ ATTR = "attribute_value" and @ ATTR = "attribute_value"
Note: @ indicates the attribute prefix, and @ ATTR indicates the attribute ATTR.
VII,Attribute ()
Meaning: returns the set of all attribute nodes, which is equivalent to "@ *".
Example: search for all resume elements. If the conditions are met, at least one attribute value is "ABC"
Resume [$ any $ attribute () = 'abc'] or resume [$ any $ @ * = 'abc']
Search for all resume elements. If the conditions are met, at least one sub-element has an Attribute Value of "ABC"
Resume [$ any $ */attribute () = 'abc'] or resume [$ any $ */@ * = 'abc']
8,Comment ()
Meaning: return all comment nodes
Example:
Resume [$ any $ comment () = 'yu Xichu's resume ']
Indicates searching for statements containing comments
<! -- Yu Xichu's resume -->
<Resume>
IX,CDATA ()
Meaning: return the set of all CDATA nodes.
Example:
Resume [$ any $ CDATA () = 'yu Xichu's resume ']
Indicates to search for statements containing the following (must be a direct subnode)
<! [CDATA [Yu Xichu's Resume]>
<Resume>
10,Node ()
Meaning: returns the set of all nodes except the root node and attribute node in the current context, which is equivalent
"* | Pi () | comment () | text ()"
Example: search for all the elements resume. The last node name is "skill"
Resume [node () [end ()]! Nodename () = 'skill']
Find the first node of all resume elements: Resume/node () [0]
XI,Textnode ()
Meaning: return the set of all vertices of the text type.
Example: Find the second text node of each P element
P/textnode (1) or P! Textnode (1)
12,Text ()
Meaning: returns a set of all vertices that represent a text string, equivalent to "CDATA () | textnode ()";
This article introduces this point. There is another functionDate ()An error occurs on my machine so that the browser is automatically closed. There is also a functionPi ()I have not found an appropriate application method, so I will not introduce it. The next section describes how to use scripts in XSL.