Method of objects in DOM

xiaoxiao2021-03-06  114

Series Function Xiang Hao ---- Method of Objects in DOM

This issue introduces multiple XSL for VBScript, JScript increases, attribute to give full play to the advantage of XML, useful in , Decoration or , , < XSL: WHEN> EXPR properties.

First, AbsolutechildNumber

Meaning: Return Node relative to all the brothers (regardless of the name of the name)

Syntax: AbsolutechildNumber (NODE)

Parameters: Node - object, want to return the node of the number.

Example:

1. Assume that the document structure is: , where Document is the top-level node, the following expression will output

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

2, determine the current node relative to the serial number of all its brothers

AbsolutechildNumber (this)

Second, AncStorchildNumber

Meaning: From the given junction, the serial number of the nearest ancestral node is returned according to the given ancestor node name (relative to the same name node). Returns 0 if you find no ancestors.

Syntax: AncStorchildNumber (BSTRNODENAME, PNODE)

parameter:

BSTRNODENAME - String. The name of the ancestral node searched.

PNode - object. Search the node of the start position.

Example:

Find the current node recently named Report ancestor node.

AncStorchildNumber ("Report", this)

Third, Attributes

Meaning: Return to the collection of node properties

Object.attributes

Parameters: Object - Node Object

Example:

Number of current node properties

this.attributes.length

The value of the current node third attribute

this.attributs.Item (2) .value

Or this.attributes.Item (2) .text

Or this.attributes (2) .Text

Note: If a given subscript is greater than the total sum of the attribute, it will be reduced, the subscript of the first attribute is 0.

Fourth, BaseName

Meaning: Returns the basic name of the name spatial restriction, ie not including the name prefix

Grammar: Object.basename

Parameters: Object - Node Object

Example: Basic name for the current node: this.basename

V. ChildNumber

Meaning: Return to the serial number relative to the same class

Grammar: ChildNumber (Object)

Parameters: Object ─? 岬 韵? / P>

Example: Assume that the XML document structure is as follows

If the current node is Z, ChildNumber (this) returns 1, and AbsolutechildNumber (this) returns 3.

Sixth, Datatype

Meaning: Set or read the data type of node

Syntax: Setting Node Data Type Object.DataType = ObjValue Read Node ObjValue = Object.DataType

Parameters: Object - Node Object

Example: Read the data type of the current node

DTTYPE = this.DataType

Seven, depth

Meaning: The designated node appears in the depth of the document tree, that is, the node is located in the first few layers of the document, and the top layer is located

The first layer, the root node (ie the node expressed by "/") is located at 0

Syntax: DEPTH (PNODE)

Parameters: PNODE - Node Object

Example: the depth of the current node

DEPTH (this)

Eight, Firstchild, Lastchild

Meaning: Returns the first sub-node of the node (or the last sub-node).

Syntax: pnode.firstchild

Pnode.lastchild

Parameters: PNODE - Node Object

Example: The name of the first node of the current node

this.firstchild.nodeName

Nine, Formatindex

Meaning: Format the integer provided with the specified count system.

Syntax: Formatindex (Lindex, BStrFormat)

parameter:

LINDEX - integer value or variable

BStrformat - data format, optional value A, A, I, I, 1, 01 (with 0 header), if the number of fixed lengths is required, such as 0001,0002 is very useful)

Example: Current Number of Current Number Roman Digital Number

Formatindex (ChildNumber (this), "i")

Ten, FormatNumber

Meaning: The value is output in the specified format.

Grammar: FormatNumber (DBLNumber, BStrFormat)

Parameters: Description With FormatNumber, the difference is that the formatted can be a decimal

Example: Value formatted to the variable A is two decimal formatNumber (a, "#. 00")

11. HaschildNodes

Meaning: If the node has a sub-node, returns true (-1), otherwise false (0)

Syntax: pnode.haschildnodes ()

Note: Unlike the functions previously described, this function must have an empty bracket.

Example: Judging whether the current node has a sub-node

this.haschildnodes

Twelve, Namespaceuri, Prefix

Meaning: Returns the global resource identifier (or prefix) of node namespace

Syntax: pnode.namespaceuri

Pnode.prifix

Thirteen, nextsibling, previoussibling, ParentNode

Meaning: Return to the next brother (or the previous brother, or the father of the node)

Syntax: pnode.nextsibling

Pnode.previoussibling

pnode.parentnode

Note: Apply a ParentNode method for root nodes (ie, "/"), apply the previoussibling method for the first child node, apply the nextsibling method for the last child's node, can cause errors, which can pass this relationship operator == (Equal to) and! = (Not equal) to determine if a node is specified node, format is pnode1 = pnode2 or pnode2! = Pnode2. Fourteen, nodename

Meaning: Returns a specific string of elements, attributes, entrances, or other type of node

Syntax: pnode.nodeename

Example: the name of the current node

this.nodename

Fifteen, nodetype, nodetypeString

Meaning: Numerical form of the type of node (or string form)

Syntax: pnode.nodetype or pnode.nodetypeString

return value:

Node Type Node Type Number Node Type String

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"

XVI, NodeTypedValue

Meaning: Returns the value of node with a predefined data type of node

Syntax: pnode.nodetyped accuue

Example: Assume that the data type of the current node is fixed.14.4, the following example will return the value of the node with a value rather than the text

this.nodetypedValue

Seventeenth, NodeValue

Meaning: Back to the text

Grammar: pnode.nodevalue

Note: This method is not used for elemental sources, available for attributes, cdata, annotations, text and other nodes.

Example: Current value of the first attribute of the element

THIS.Attributes (0) .NodeValue

Text within the current element (assuming that only text in this element, no other elements, " text , it is recommended to give more exact usage several times)

this.firstchild.NodeValue

Eighteen, OwnerDocument

Meaning: Returns the root of the document containing the node

Syntax: pnode.ownerdocument

Note: This method is used for the root node of the document.

19, SelectNodes

Meaning: The given style matching is applied to the current node and returns a match collection.

Syntax: pnode.selectnodes ("pattern")

Tip: Pattern's writing and value type, which is expressed in "/"

Depart from the root of the document; "//" starts all the nodes of the document; ".."

Indicates that from the parent node of the current node; if you want to search from the current node, you can't have the above special characters.

Example: Number of elements with the same name with the current node in their parent elements

ChildNumber (this.selectnodes ("../" this.nodeename " [end ()] "). Item (0))

Number of elements of the current element name "skill"

ChildNumber ("Skill [end ()]"). Item (0)) 20, Selectsinglenode

Meaning: Similar to SelectNodes, different returns only the first node, not the gathering collection

Syntax: pnode.selectsinglenode ("pattern")

Example: Number of elements with the same name with the current node in their parent elements

ChildNumber (this.selectsinglenode ("./" this.nodeename " [end ()] "))

Number of elements of the current element name "skill"

ChildNumber (this.selectsinglenode ("Skill [end ()]"))

21, Text

Meaning: Return to the text content with its subtree

Syntax: pnode.text

Example: text content in the entire document

this.ownerDocument.text

Current element and its subtree text content

this.Text

Twenty-two, XML

Meaning: return node and its descendants XML

Syntax: pnode.xml

Example: the XML content of the current document

this.ownerDocument.xml

There are several functions that are not introduced, listed in response, if you are interested, please visit http://msdn.microsoft.com Get a detailed description.

FormatTime (Vartime, Bstrformat, VARDestLocale)

Formatdate (Vardate, BstrFormat, VARDestLocale)

Apendchild (Newchild)

Definition

Clonenode

INSERTBEFORE (Newchild, Refchild)

parse

RemoveChild (Oldchild)

Replacechild (NewChild, Oldchild)

Specified

TransformNode (Stylesheet)

TransformNodetoObject (Stylesheet, OutputObject)

UNIQUEID (PNode) XSL function

XSL function

Learn the XSL style method in this issue, you can use the XSL element , , , , TEST attributes are screened to the range of elements to provide 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 content 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, meets at least one child element with 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-101471.html

New Post(0)