This period learns about XSL style methods for use with the select Properties of XSL elements <xsl:for-each>, <xsl:value-of>, <xsl:template>, <xsl: Apply-templates> 's match properties, <xsl:if>, <xsl:when> test Properties, filter the scope of the element to provide greater flexibility.
XML is like DHTML (Dynamic HTML), these nodes are all objects, and these objects are layered, starting from the root node to form a hierarchical clear tree structure, which forms the Document Object model DOM, which is based on the object's properties, method to achieve the purpose of accessing the control XML node.
We are not going to elaborate on the XML DOM in detail, as it can be written in a more extensive tutorial, and we'll discuss some common methods to get a general idea of the DOM's object approach.
Note: From the beginning of this period, all samples no longer provide complete source code, if you do not understand, please read the previous seven, and practicing.
One, End ()
Meaning: Returns the last element in the collection.
Example: Output last Resume
Suppose the XML file format is:
... <resume>...</resume>......<resume>...</resume> .......
The contents of the corresponding XSL file are:
<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>
Second, index ()
Meaning: Returns the position of the element in the collection, and the return value is an integer in which the first element returns 0.
Example: Return to the previous three resumes.
Resume[index () $le $]
Note: index () is related to the parent element, see the following example:
<x>
<y/>
<y/>
</x>
<x>
<y/>
<y/>
</x>
Returns the first <y> in all <x>
X/y[index () =0] or x/y[0]
Third, nodename ()
Meaning: Returns the name of the element, which is the tag name.
Example: Select any element, if its name (that is, the tag name) equals "name":
*[nodename () = ' name '] or *[name]
Four, number ()
Meaning: Converts a value to a numeric form and returns null if it is not a value, requiring parameters.
Example: CV of person aged (age) less than 30 years old (resume):
Resume[number (age) $lt $] or resume[age$lt$30]
V. NodeType ()
Meaning: Returns the node type, resulting in a numeric value. The following is a list of return values:
Node type |
Node Type value |
Description of the character form of the 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 ' |