This issue introduces multiple methods and attributes added by XSL to VBScript and JScript, to give full play to the advantages of XML, and is used to write expressions in <xsl:script>, <xsl:eval> tags or the expr attributes of <xsl:if>, <xsl:when>.
1. absoluteChildNumber
Meaning: Returns the sequence number of the node relative to all its brothers (regardless of the same name or not).
Syntax: absoluteChildNumber(node)
Parameters: node ── Object, to return the numbered node.
Example:
1. Assume that the document structure is: <document><head/><body/></document>, where document is the top-level node, the following expression will output:
<xsl:eval>
absoluteChildNumber(('/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 closest ancestor node (relative to the node with the same name) based on the given ancestor node name from the given ancestor node name. If the ancestor is not found, return 0.
Syntax: ancestorChildNumber(bstrNodeName, pNode)
parameter:
bstrNodeName ── string. The name of the ancestral node being searched for.
pNode ── object. Search for the node at the start position.
Example to find the nearest node named report ancestor node:
ancestorChildNumber('report',this)
III. Attributes
Meaning: Returns a collection of node attributes.
grammar:
Parameters: object ── node object.
Example: Number of current node attributes
The value of the third attribute of the current node
(2).value
or
(2).text
or
(2).text
Note: If the given subscript is greater than the sum of the attributes, it will be an error, and the subscript of the first attribute is 0.
4. baseName
Meaning: Returns a basic name with name space limitations, that is, does not include the name prefix.
grammar:
Parameters: object ── node object
Example, the basic name of the current node:
5. childNumber
Meaning: Returns the sequence number of the node relative to the compatriot of the same name.
Syntax: childNumber(object)
Parameters: object ── node object
For example, assume that the XML document structure is as follows:
<x><y><z></z></y></x>
If the current node is z, childNumber(this) returns 1, and absoluteChildNumber(this) returns 3.
6. dataType
Meaning: Set or read the data type of node.
Syntax: Set the data type of node =objValue
The data type of the read node objValue=
Parameters: object ── node object.
Example, read the data type of the current node:
dtType=
7. Depth
Meaning: Specify the depth at which node appears on the document tree, that is, the node is located at the level of the document, the top-level node is located at the first layer, and the root node (i.e. the node represented by "/") is located at the level 0.
Syntax: depth(pNode)
Parameters: pNode ── node object
Example, the depth of the current node:
depth(this)
8. FirstChild, lastChild
Meaning: Returns the first child node (or the last child node) of the node.
grammar:
Parameters: pNode ── node object
Example, the name of the first node of the current node:
9. formatIndex
Meaning: Format the provided integer with the specified counting system.
Syntax: formatIndex(lIndex, bstrFormat)
parameter:
lIndex ── integer value or variable
bstrFormat ── Data format, optional values are a, A, i, I, 1, 01 (in the form of a numerical value starting with 0, which is very useful if a fixed-length number is required, such as 0001 and 0002).
Example, the capital Roman numeral number of the current node:
formatIndex(childNumber(this),'I')
10. formatNumber
Meaning: Output numeric values in the specified format.
Syntax: formatNumber(dblNumber, bstrFormat)
Parameter: The description is the same as formatNumber, the difference is that the formatted number can be a decimal.
Example, format the value of variable a to two decimal places:
formatNumber(a,'#.00'):
11. hasChildNodes
Meaning: Return true (-1) if the node has child nodes, otherwise false (0).
grammar:()
Note: Unlike the function introduced before, this function must be followed by an empty bracket.
Example, determine whether the current node has child nodes:
12. namespaceURI, prefix
Meaning: Returns the global resource identifier (or prefix) of the node name space.
grammar:
13. NextSibling, previousSibling, parentNode
Meaning: Returns the next brother of the node (or the previous brother, or the parent node of the node).
grammar:
Note: Applying parentNode method to the root node (i.e. "/"), applying previousSibling method to the first child node, and applying nextSibling method to the last child node will all cause errors. You can use this relationship operator == (equal to) and != (not equal to) to determine whether a node is a specified node. The format is pNode1 = pNode2 or pNode2 != pNode2.
14. nodeName
Meaning: Returns an element, attribute, entry name, or other type of node a specific string.
grammar:
Example, the name of the current node:
Fifteen, nodeType, NodeTypeString
Meaning: Returns the numerical form (or string form) of the type of the node.
Syntax: or
Return value:
Node type | Node type value | Character form description of nodes |
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' |
16. nodeTypedValue
Meaning: Returns the value of the node as the predefined data type of the node.
grammar:
Example, assuming that the data type of the current node is fixed.14.4, the following example will return the value of the node as a numeric value, instead of a string in text:
17. nodeValue
Meaning: Returns the text of the node.
grammar:
Note: This method is not used for element-class nodes, but can be used for attributes, CDATA, annotations, text and other nodes.
Example, the value of the first attribute of the current element:
(0).nodeValue
Text in the current element (assuming that there is only text in this element and no other elements, that is, <mark>text</mark>, it is recommended to try it a few more times to master its exact usage).
18. OwnerDocument
Meaning: Returns the root of the document containing the node.
grammar:
Note: There will be an error when this method is used for the root node of the document.
Nineteen, selectNodes
Meaning: The given style match is applied to the current node and returns the matching node collection.
Syntax: ('pattern')
Tip: The writing of pattern is similar to the value of the select property of <xsl:for-each>, where "/" starts with "/" means searching from the root of the document; starting with "//" means traversing all nodes of the document; starting with ".." means starting with ".." means starting with "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, the number of elements with the same name as the current node in its parent element:
childNumber(("../"++"[end()]").item(0))
The number of elements with the name "skill" in the current element:
childNumber(("skill[end()]").item(0))
Twenty, selectSingleNode
Meaning: Similar to selectNodes, the difference only returns the matching first node, not the node collection.
Syntax: ('pattern')
Example, the number of elements with the same name as the current node in its parent element:
childNumber(("../"++"[end()]"))
The number of elements with the name "skill" in the current element:
childNumber(("skill[end()]"))
21. text
Meaning: Returns the text content in the node and its subtree.
grammar:
Example, text content in the entire document:
Text content of the current element and its subtree:
Twenty-two, xml
Meaning: Returns the XML representation of the node and its descendants.
grammar:
Example, XML content of the current document:
There are several other functions that are not introduced and are listed below for reference. If you are interested, please visit the detailed description.
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)