Wednesday, February 18, 2026

XSLT Xpath Functions

 

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:

Number ceiling(value)The result will be greater than or equal to the value of the given argument.

concat()

The concat function combines multiple strings into one string. The syntax for this function is:

String concat(value1, value2+)

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:

boolean contains(value, substring)

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:

number count(nodes)The function does not count the child nodes in the given node-set.

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:

node-set current()

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-group() as item()*

 The <xsl:for-each-group> element processes a group of related items during iteration process. The group of items processed currently by this element is called the current group.

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:

current-grouping-key() as xdt:anyAtomicType

document()

The document() function loads the XML document and identifies the root node in the source document. The syntax for this function is:

number document(uri) number document(uri, base-uri)

element-available()

The element-available() function checks whether an XSLT element is available or not. The syntax for this function is:

boolean element-available(name)

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:

boolean false()

floor()

The floor() function returns the nearest great integer for the given number. The syntax for this function is:

number floor(value)

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:

string format-number(value, format) number format-number(value, format, name)

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:

format-dateTime($value as xs:dateTime?,$picture as xs:string, $date-format-name as xs:string) as xs:string? format-dateTime($value as xs:dateTime?,$picture as xs:string) as xs:string?

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:

format-date ($value as xs:dateTime?,$picture as xs:string, $date-format-name as xs:string) as xs:string? format-date ($value as xs:dateTime?,$picture as xs:string) as xs:string?

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:

format-Time($value as xs:dateTime?,$picture as xs:string, $date-format-name as xs:string) as xs:string? format-Time($value as xs:dateTime?,$picture as xs:string) as xs:string?

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:

boolean function-available(name)

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()

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:

node-set id(value)

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:

node-set key(name,value)

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:

boolean lang(language)

last()

The last() function returns the number assigned to the last node in the document. The syntax of this function is:

number last()

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:

string local-name() string local-name(node)

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:

string name() string name(node)

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:

string namespace-uri() string namespace-uri(node)

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:

string normalize-space() string normalize-space(value)

not()

If the argument of this function is true(), it returns false and vice versa. The syntax for this function is:

boolean not(condition)

number()

The number() function converts the give value into a numeric value. The syntax for this function is:

number number() number number(value)

position()

The position() function finds the position of a node in a document. The syntax for this function is:

number position()

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:

replace(value, substring1, substring2)

round()

The round() function rounds the given decimal value to the nearest integer. The syntax for this function is:

number round(value)

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:

sort($input-sequence as item()*, $sort-spec-name as xs:string) as item()*

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:

boolean starts-with(value, substring)

string()

The string() function converts the given value into a string value. The syntax for this function is:

string string() string string(value)

string-length()

The string-length() function finds the length of the given string. The syntax for this function is:

number string-length() number string-length(value)

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:

string substring(value, start) string substring(value, start, length)

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:

string substring-after(value, substring)

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:

string substring-before(value, substring)

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:

system-property(name)

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:

string translate(value, from, to)

true()

The true() function is used in XPath expressions as a boolean constant. The syntax for this function is:

boolean true()

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:

string unparsed-entity-uri(name)

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:

unparsed-text($href as string?) as string

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 &lt and &amp.

No comments:

Post a Comment

SOA Overview Part-1

  Middleware It provides a mechanism for the process to interact with other processes running on multiple network machines. Advantages...