XSL function

xiaoxiao2021-03-06  78

Learn the XSL style method, you can use the XSL element ,

Value-of>, SELECT attribute, Match property, , Test property, filtering the range of elements, Greater flexibility.

The XML is the same as DHTML (dynamic HTML), and these nodes are objects, and these objects are hierarchical, and the root node begins constitutes a hierarchical tree structure, which forms a document object model DOM. Through the properties of the object, the method reaches the purpose of the access control XML node.

We don't intend to explain in detail one by one here, because this can be written into a more than one tutorial, we will discuss some common methods first, in order to have a general understanding of the object method of the DOM.

Note: From this issue, all examples no longer provide complete source code. If you don't understand, please read the seven phases in front of the previous group and do it.

First, End ()

Meaning: Returns the last element in the collection.

Example: Output last resume

Assume that the XML file format is:

...... ... ... ... ......

The corresponding XSL file is:

......

or

......

Second, INDEX ()

Meaning: Returns the position of the element in the collection, the return value is an integer, where the first element returns 0

Example: Return to three resumes

Resume [index () $ l $ 3]

Note: Index () is related to the parent element, see the case:

Returns the first in

X / y [index () = 0] or x / y [0]

Third, Nodename ()

Meaning: Returns the name of the element, ie the marking name

Example: Select any elements, if its name (ie, the tagname) is equal to "name"

* [nodename () = "name"] or * [name]

Fourth, Number ()

Meaning: Convert value into numerical form, if not numerical, return empty, required parameters

Example: Jeff Weiner (AGE)? 0-year-old resume (Resume)

Resume [Number (AGE) $ LT $ 30] or Resume [AGE $ LT $ 30]

Five, nodetype ()

Meaning: Return the node type, resulting in a value. The following is a list of return values:

Node type node type value node character form description

ELEMENT1 "ELEMENT"

Element Attribute 2 "Attribute" Markup-Delimited Region of Text 3 "TEXT"

Processing Instruction 7 "Processing_instruction"

Comment8 "comment"

Document Entity9 "Document"

Sixth, value ()

Meaning: Returns the value of elements or attributes

Example: Value () is the default method of the element or attribute, the following representation is equivalent

Name! Value () = "name" with name = "name"

@ attr = "attribute_value" with @ attr = "attribute_value"

Note: @ is a property prefix, @ attr representation is attribute ATTR

7. Attribute ()

Meaning: Returns a collection of all attribute nodes, equivalent to "@ *"

Example: Looking for all Resume elements, the value of at least one property is satisfied is "ABC"

Resume [$ ATTRIBUTE () = "abc"] or resume [$ any $ @ * = "ABC"]

Look for all Resume elements, meet at least one child element having a property of "ABC"

Resume [$ ANY $ * / attribute () = "abc"] or resume [$ any $ * / @ * = "abc"]

Eight, comment ()

Meaning: Returns all comment nodes

Example: for example

ResMe [$ any $ comment () = "Qi Xi's resume"]

Represents looking for a comment statement

Elements

Nine, cdata ()

Meaning: Returns a collection of nodes of all CDATA types

Example: for example

Resume [$ any $ cdata () = "Qi Xi's resume"]

Indicates looking for the following statement (must be a direct sub-node)

Elements

Ten, node ()

Meaning: Returns a collection of all nodes other than root nodes and attribute nodes in the current context environment, equivalent

"* | Pi () | comment () | text ()"

Example: Looking for all Elements Resume, the name of its last node is "Skill"

Resume [Node () [end ()]! nodename () = "skill"]

Find the first node of all resume elements: resume / node () [0]

11. TextNode ()

Meaning: Returns a collection of nodes of all text types

Example: Find the second text node of each P element

P / TextNode (1) or P! TextNode (1)

Twelve, text ()

Meaning: Returns all sets of nodes indicating the text string, equivalent to "cdata () | textNode ()";

The content of this issue will be introduced, and another function date () has an error in my machine, making the browser automatically shut down, and a function PI () I have not found an appropriate application method, I don't introduce it. Using the script in XSL in the next period.

转载请注明原文地址:https://www.9cbs.com/read-121622.html

New Post(0)