Xue XSL (7)

Source: Internet
Author: User
Tags processing instruction xsl file
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>


<XSL: templates match = "resume [end ()]"> ...... </XSL: templates>


<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:









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 attribute



Markup-delimited region of Text



Processing Instruction






Document entity




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


Resume [$ any $ comment () = 'yu Xichu's resume ']

Indicates searching for statements containing comments

<! -- Yu Xichu's resume -->




Meaning: return the set of all CDATA nodes.


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]>



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.

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.