XPath Functions
XPath functions are referred by the namespace URI http://www.w3.org/2003/05/xpath-functions.
The XPath functions enable you to handle numeric values, string values, Boolean values, node-sets, and nodes.
the XPath functions also work with XPath expressions.
boolean()
The boolean() function converts any value into a boolean value. The syntax for this function is:
boolean boolean(value)
ceiling()
The ceiling function returns the nearest small integer for the given value. The syntax for this function is:
concat()
The concat function combines multiple strings into one string. The syntax for this function is:
contains()
This function checks whether a specific substring exists in a given string and returns a boolean value depending on a test value. The syntax for this function is:
If the string contains the substring, the function returns true or returns false when the substring is not found. If the arguments that you pass are not of string data type, the function converts them into string data type.
count()
The count() function returns the number of nodes in a node-set. The syntax for this function is:
current()
The current() function returns the node that contains single node. The return data type of this function is a node-set. The syntax for the current() function is:
When you process the <xsl:apply-templates> and <xsl:for-each> elements, the selected nodes become the current node.
current-group()
The current-group() function returns a group of related items. This function requires no arguments. The syntax for the current-group() function is:
current-grouping-key()
The current-grouping-key() function returns the current-grouping-key that is used by the <xsl:for-each-group> element. The syntax for this function is:
document()
The document() function loads the XML document and identifies the root node in the source document. The syntax for this function is:
element-available()
The element-available() function checks whether an XSLT element is available or not. The syntax for this function is:
The element-available() function returns a boolean value depending on the availability of the element The argument that you pass must be of string data type, if not, the function converts the argument into a string.
false()
The false() function returns the value false and is used as a boolean constant in XPath expressions. The syntax for this function is:
floor()
The floor() function returns the nearest great integer for the given number. The syntax for this function is:
The argument to the floor() function should be a numeric value. If the argument is not numeric, the function converts it into a numeric value.
format-number()
The format-number() function formats a given number by applying a pattern to it. The syntax for this function is:
The function converts numbers to string values. This function is used when the number to be displayed in the resultant document needs to occupy a fixed number of character positions. The <xsl:decimal-format> element defines the characters and symbols required for the format-number function.
format-dateTime()
The format-dateTime() function formats the specified date and time. The syntaxes for this function are:
The name of the <xsl:data-format> element is passed as the argument to this function.
format-date()
The format-date() function formats the given date specific to a picture string that is passed as an argument. The syntaxes for this function are:
The name of the <xsl:data-format> element is passed as the argument to the function.
format-Time()
The format-Time() function formats the given time specific to the picture string that is passed as the argument. The syntaxes for this function are:
The name of the <xsl:data-format> element is passed as the argument to the function.
function-available()
The function-available() function checks whether the given function is available or not. The syntax for this function is:
The function that you pass as an argument can be either an XPath function or an extension function.
generate-id()
The generate-id() function returns a unique string value for every node in the document to enable identify the node. The syntax for this function is:
string generate-id(node)
The generated id for each node differs from processor to processor.
Id()
This function identifies the attribute declared of the type ID in a DTD or schema. The Id() function returns the node or node-set that contains the attribute. The syntax for this function is:
key()
The key() function is used with the <xsl:key> element. This function finds the nodes in an XML document using the name of the <xsl:key> element as one of the arguments. The syntax for the key() function is:
lang()
The lang() function checks whether the language passed as a argument to this function is equal to language of the context node defined by the xml:lang attribute. The syntax for this function is:
last()
The last() function returns the number assigned to the last node in the document. The syntax of this function is:
When you are processing a list of nodes, the nodes are numbered from the context node. Using the last() function, which numbers the last node, you can determine the context size. You can use this function along with <xsl:apply-template> and <xsl:for-each> elements to find the number of nodes selected.
local-name()
The local-name() function retrieves a node name from the source document. The syntax for this function is:
If the name of the node contains prefix, this function returns a qualified name without the prefix.
name()
The name() function returns the name of the given node. The syntax of this function is:
If the node is declared using the namespace, this function returns a <prefix-name:element-name> element.
namespace-uri()
The namespace-uri() function returns the namespace URI of the given node in the source document. The syntax for this function is:
normalize-space()
The normalize-space() function eliminates the white spaces in the prefix and suffix of the given string. The syntax for this function is:
not()
If the argument of this function is true(), it returns false and vice versa. The syntax for this function is:
number()
The number() function converts the give value into a numeric value. The syntax for this function is:
position()
The position() function finds the position of a node in a document. The syntax for this function is:
This function returns the number assigned to the node. If this function is used with the <xsl:apply-templates>,<xsl:key>, and <xsl:for-each> elements, it displays the position of the node after sorting.
replace()
The replace() function replaces the substring2 with the substring1 in the given string. The syntax for this function is:
round()
The round() function rounds the given decimal value to the nearest integer. The syntax for this function is:
sort()
The sort() function sorts the elements using the name specified in <xsl:sort-key> element as one of its arguments. The syntax of this function is:
The argument $input-sequence as item()* denotes the initial sequence for sorting. The $sort-spec-name as xs:string argument is the value defined in the <xsl:sort-key> element.
starts-with()
The starts-with() function checks whether a string starts with a particular substring or not and returns true or false accordingly. The syntax for this function is:
string()
The string() function converts the given value into a string value. The syntax for this function is:
string-length()
The string-length() function finds the length of the given string. The syntax for this function is:
substring()
The substring() function returns all characters in a given string value starting from the position specified by the start argument. The syntax for this function is:
You can use the length argument to return a substring that contains characters between the start position and the position specified by the length argument.
substring-after()
The substring-after() function returns a substring present after the occurrence of the given substring in a string. The syntax for this function is:
substring-before()
The substring-before() function returns a substring present before the occurrence of the given substring in a string. The syntax for this function is:
system-property()
The system-property() function identifies the value of system properties, such as xsl:version, xsl:vendor, and xsl:vendor-url, and returns the values. The syntax for this function is:
translate()
The translate() function replaces a specified number of characters with another set of characters in a given string. The syntax for this function is:
true()
The true() function is used in XPath expressions as a boolean constant. The syntax for this function is:
unparsed-entity-uri()
The unparsed-entity-uri() function retrieves the unparsed entities declared in the DTD of a source document. The syntax for this function is:
You need to pass the name of an unparsed entity in the DTD as an argument to this function. The function returns the corresponding URI as a string value.
unparsed-text()
The unparsed-text() function reads the content in the external file and returns the content as a string to the source file. The syntax for this function is:
The argument href contains the URI of the external file in a string format. If the file contains characters, such as < and &, these characters are returned by the function as < and &.
No comments:
Post a Comment