Follow me. XSL (7) XSL function one

Source: Internet
Author: User
Tags numeric numeric value object model processing instruction tag name xsl xsl file

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 '

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.