Detailed description of XML Functions

Source: Internet
Author: User
Tags processing instruction xsl xsl file
---- Methods of objects in Dom

This section describes the methods and attributes added by multiple XSL for VBScript and JScript to give full play to the advantages of XML, which are used for <XSL: SCRIPT>, <XSL: eval> compile the expression within the tag or the expr attribute of <XSL: If> and <XSL: When>.

1. absolutechildnumber

Meaning: return the sequence number of the node relative to all its brothers (regardless of whether the name is the same)

Syntax: absolutechildnumber (node)

Parameter: node-object. The node number to be returned.

Example:

1. Assume that the document structure is: <document>

<XSL: eval>

Absolutechildnumber (this. selectnodes ("/document/body"). Item (0 ))

</XSL: eval>

2. Determine the serial number of the current node relative to all its brothers.

<XSL: eval> absolutechildnumber (this) </XSL: eval>

2. ancestorchildnumber

Meaning: return the sequence number of the nearest ancestor Node Based on the given ancestor node name (relative to the Same Name node ). If no ancestor is found, 0 is returned.

Syntax: ancestorchildnumber (bstrnodename, pnode)

Parameters:

Bstrnodename ── string. Name of the searched ancestor node.

Pnode-object. Search for the Start Node.

Example:

Find the closest report ancestor node to the current node.

Ancestorchildnumber ("Report", this)

Iii. Attributes

Meaning: return the set of node attributes.

Syntax: object. Attributes

Parameter: Object-Node object

Example:

Number of current node attributes

This. Attributes. Length

Value of the third attribute of the current node

This. attributs. Item (2 ).Value

Or this. Attributes. Item (2). Text

Or this. attributes (2). Text

Note: If the given subscript is greater than the sum of attributes minus 1, an error occurs. The subscript of the first attribute is 0.

Iv. basename

Meaning: returns the basic name with namespace restrictions, that is, excluding the name prefix.

Syntax: object. basename

Parameter: Object-Node object

Example: Basic name of the current node: This. basename

V. childnumber

Meaning: return the serial number of the node relative to the same name compatriot

Syntax: childnumber (object)

Parameter: Object? Leng Yun? /P>

Example: assume that the XML document structure is as follows:

<X> <Y> <z/> <Y/> </x>

If the current node is Z, childnumber (this) returns 1, while absolutechildnumber (this) returns 3.

6. datatype

Description: sets or reads the Data Type of a node.

Syntax: Set the Data Type of the Node object. datatype = OBJValue

Data Type of the read node OBJValue= Object. datatype

Parameter: Object-Node object

Example: Read the Data Type of the current node

Dttype = This. datatype

VII. Depth

Meaning: Specify the depth of the node that appears on the document tree, that is, the node is located at the layer of the document, and the top node is located

At the first layer, the root node (that is, the node represented by "/") is located at Layer 0th.

Syntax: depth (pnode)

Parameter: pnode-Node object

Example: depth of the current node

Depth (this)

8. firstchild and lastchild

Meaning: return the first subnode (or the last subnode) of the node ).

Syntax: pnode. firstchild

Pnode. lastchild

Parameter: pnode-Node object

Example: name of the first node of the current node

This. firstchild. nodename

9. formatindex

Meaning: format the provided integer with the specified counting system.

Syntax: formatindex (lindex, bstrformat)

Parameters:

Lindex ── integer value or variable

Bstrformat-data format. Optional values include a, a, I, I, 1, and 01 (in the form of a value with 0 headers, it is useful if Fixed Length numbers such as 0001 and 0002 are required)

Example: upper-case roman numerals of the current node

Formatindex (childnumber (this), "I ")

10. formatnumber

Meaning: outputs a value in a specified format.

Syntax: formatnumber (dblnumber, bstrformat)

Parameter: The description is the same as formatnumber. The difference is that the format can be decimal.

Example: format the value of variable A as two decimal formatnumber (a, "#. 00 ")

11. haschildnodes

Meaning: If a node has a subnode, true (-1) is returned; otherwise, false (0) is returned)

Syntax: pnode. haschildnodes ()

Note: Unlike the previously described function, this function must contain an empty parenthesis.

Example: determine whether the current node has a subnode

This. haschildnodes

12. namespaceuri and prefix

Meaning: return the Global Resource Identifier (or prefix) of the node namespace)

Syntax: pnode. namespaceuri

Pnode. prifix

13. nextsibling, previussibling, and parentnode

Meaning: return the next brother of the node (or the parent node of the previous brother or node)

Syntax: pnode. nextsibling

Pnode. previussibling

Pnode. parentnode

Note: Applying the parentnode Method to the root node (I .e. "/"), applying the previoussibling Method to the first child node, and applying the nextsibling Method to the last child node will cause errors, you can use this relational operator = (equal to) and! = (Not equal to) to determine whether a node is a specified node, in the format of pnode1 = pnode2 or pnode2! = Pnode2.

14. nodename

Meaning: return an element, attribute, entry name, or a specific string of other types of nodes.

Syntax: pnode. nodename

Example: name of the current node

This. nodename

15th, nodetype, nodetypestring

Meaning: return the numeric form (or string form) of the node type)

Syntax: pnode. nodetype or pnode. nodetypestring

Return Value:

Node Type

Node Type Number node type string

Element

1

"Element"

Element attributes

2

"Attribute"

Markup-delimited region of Text

3

"Text"

Processing Instruction

7

"Processing_instruction"

Comment

8

"Comment"

Document entity

9

"Document"


16. nodetypedValue

Meaning: return the value of a node based on the predefined Data Type of the node.

Syntax: pnode. nodetypedValue

Example: assume that the data type of the current node is fixed.14.4. In the following example, the value of the node is returned as a numerical value instead of a text string.

This. nodetypedValue

17. NodeValue

Meaning: return the text of the node.

Syntax: pnode. NodeValue

Note: This method is not used for element nodes. It can be used for attributes, CDATA, comments, text, and other nodes.

Example: the value of the first attribute of the current element

This. attributes (0). NodeValue

Text in the current element (assuming that the element contains only text, no other elements, that is, <mark> text </mark>, we recommend you try it several times to learn its exact usage)

This. firstchild. NodeValue

18. ownerdocument

Meaning: return the root of the document containing the node

Syntax: pnode. ownerdocument

Note: This method is used for root node errors of documents.

Nineteen, selectnodes

Meaning: The given style match is applied to the current node and the matched node set is returned.

Syntax: pnode. selectnodes ("pattern ")

Tip: The expression of pattern is similar to the value of the select attribute of <XSL: For-each>, which starts "/".

Search from the root of the document; traverse all nodes of the document starting with "//"; start "..."

Start from the parent node of the current node. If you want to search down from the current node, you cannot start with the above special characters.

Example: number of elements with the same name as the current node in its parent Element

Childnumber (this. selectnodes ("../" + this. nodename + "[end ()]"). Item (0 ))

Number of elements in the current element named "skill"

Childnumber (this. selectnodes ("skill [end ()]"). Item (0 ))

20. selectsinglenode

Meaning: similar to selectnodes, only the matching first node instead of the node set is returned.

Syntax: pnode. selectsinglenode ("pattern ")

Example: number of elements with the same name as the current node in its parent Element

Childnumber (this. selectsinglenode ("../" + this. nodename + "[end ()]")

Number of elements in the current element named "skill"

Childnumber (this. selectsinglenode ("skill [end ()]")

21. Text

Meaning: return the node and the text content in its subtree

Syntax: pnode. Text

Example: Text Content in the entire document

This. ownerdocument. Text

Text Content of the current Element and Its subtree

This. Text

22. xml

Meaning: return the XML Representation of the node and its descendants.

Syntax: pnode. xml

Example: XML content of the current document

This. ownerdocument. xml

Several other functions are not introduced and listed below for reference. If you are interested, please visit the http://msdn.microsoft.com for detailed instructions.

Formattime (vartime, bstrformat, vardestlocale)

Formatdate (vardate, bstrformat, vardestlocale)

Apendchild (newchild)

Definition

Clonenode

Insertbefore (newchild, refchild)

Parsed

Removechild (oldchild)

ReplaceChild (newchild, oldchild)

Specified

Transformnode (stylesheet)

Transformnodetoobject (stylesheet, outputobject)

Uniqueid (pnode)

XSL function 1


This section describes the XSL style methods, which can be used by XSL elements <XSL: For-each> and <XSL:Value-Of>, select attribute of <XSL: Template>, match attribute of <XSL: Apply-templates>, test attribute of <XSL: If>, and <XSL: When>, filters the range of elements 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 period, all examples are no longer completeSource codeIf you have any questions, read the first 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] or x/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: Age )? Resume of a 0-Year-Old user)

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 elements or attributes. The following statements are equivalent.

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>


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


11. 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 ()";

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.