Follow me. XSL (9) XSL function two

Source: Internet
Author: User
Tags eval expression integer numeric processing instruction relative xsl

This issue introduces multiple XSL methods and properties for VBScript, JScript, to give full play to XML advantages, for <xsl:script>, <xsl:eval> markup expression writing or <xsl:if>, The expr attribute of <xsl:when>.

First, Absolutechildnumber

Meaning: Returns the ordinal number of a node relative to all its siblings, regardless of the name.

Syntax: Absolutechildnumber (node)

Parameters: node── object, to return the number of nodes.

Example:

1, assuming that the document structure is: <DOCUMENT><HEAD/><BODY/></DOCUMENT>, where documents are top-level nodes, the following expression will be output:

<xsl:eval>
Absolutechildnumber (This.selectnodes ('/document/body '). Item (0))
</xsl:eval>

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

<xsl:eval>
Absolutechildnumber (This)
</xsl:eval>

Second, Ancestorchildnumber

Meaning: Returns the ordinal number of the nearest ancestor node (relative to the same node) based on the given ancestor node name, starting at the given node. Returns 0 if the ancestor is not found.

Syntax: Ancestorchildnumber (Bstrnodename, Pnode)

Parameters:

bstrnodename── string. The name of the ancestor node being searched.

pnode── object. The node where the search starts.

The example finds the nearest node named the statement ancestor node:

Ancestorchildnumber (' The ", this)

Third, attributes

Meaning: Returns a collection of node attributes.

Syntax: object.attributes

Parameter: object── Node object.

Example: Number of current node properties

This.attributes.length

The value of the third property 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 larger than the property sum minus 1, the subscript for the first property is 0.

Four, BaseName

Meaning: Returns the base name with namespace restrictions, excluding the name prefix.

Syntax: Object.basename

Parameters: object── Node Object

example, the base name of the current node:
This.basename

Five, Childnumber

Meaning: Returns the ordinal number of a node relative to a sibling of the same name.

Syntax: Childnumber (object)

Parameters: object── Node Object

example, assume that the XML document is structured as follows:

<x><y><z></z></y></x>

If the current node is Z, Childnumber (this) returns 1, and Absolutechildnumber (this) returns 3.

VI. DataType

Meaning: Sets or reads the data type of the node.

Syntax: Setting the data type of a node Object.datatype=objvalue
Read the data type of the node Objvalue=object.datatype

Parameter: object── Node object.
example, to read the data type of the current node:

Dttype=this.datatype

Seven, depth

Meaning: Specifies the depth at which the node appears on the document tree, where the node is at the top level of the document, the top-level node is at the first level, and the root node (that is, the node represented by "/") is at the No. 0 level.

Syntax: Depth (pnode)

Parameters: pnode── Node Object

example, the depth of the current node:

Depth (this)

Viii. FirstChild, LastChild

Meaning: Returns the first child node (or last child node) of a 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: The supplied integer is formatted with the specified count system.

Syntax: Formatindex (lindex, Bstrformat)

Parameters:

lindex── integer value or variable

bstrformat── data format, the optional values are a, a, I, I, 1, 01 (the numeric form preceded by 0, which is useful if a fixed-length number such as 0001, 0002 is required).

example, uppercase Roman numeral number for the current node:

Formatindex (Childnumber (this), ' I ')

Ten, FormatNumber

Meaning: Outputs a value in the specified format.

Syntax: FormatNumber (Dblnumber, Bstrformat)

Parameters: The description is the same as FormatNumber, except that the format can be decimal.

example, the value of variable A is formatted as two decimal places:
FormatNumber (A, ' #.00 '):

Xi. HasChildNodes

Meaning: Returns True (-1) If the node has a child node, or False (0).

Syntax: Pnode.haschildnodes ()

Note: Unlike the function described earlier, this function must be preceded by an empty bracket.

Example to determine whether the current node has a child node:

This.haschildnodes

12, NamespaceURI, prefix

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

Syntax: Pnode.namespaceuri
Pnode.prifix

13, NextSibling, PreviousSibling, parentnode

Meaning: Returns the next sibling of the node (or the parent node of the previous sibling, or node).

Syntax: pnode.nextsibling
Pnode.previoussibling
Pnode.parentnode

Note: Applying the ParentNode method to the root node (that is, "/"), applying the PreviousSibling method to the first child node, and applying the NextSibling method to the last child node will result in an error that can be passed through the relational operator = = (equals) and the!= (Not equal) to determine whether a node is a specified node, in the form of pNode1 = PNode2 or PNode2!= pNode2.

14, NodeName

Meaning: Returns a specific string of elements, attributes, entry names, or other types of nodes.

Syntax: Pnode.nodename

example, the name of the current node:

This.nodename

XV, NodeType, nodetypestring

Meaning: Returns the numeric form (or string form) of the type of the node.
Syntax: Pnode.nodetype or pnode.nodetypestring

return value:

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.