XPath Functions
XPath expressions consist of (1) path expressions for selecting and filtering nodes, (2) XPath functions and (3) XPath operators. About XPath expressions and how Docentric utilizes them learn more in the overview tutorial.
Boolean functions
Sample XML fragment
That is used to demonstrate how the Boolean functions work - in the Example column in the below table.
1 2 3 4 |
<ReportData xmlns="https://ax.docentric.com/" xml:lang="en-US"> <SalesInvoiceLines LineAmount="1920.0000000000" Name="Mid-Range Speaker" /> <SalesInvoiceLines LineAmount="80.0000000000" Name="Low-Range Speaker" /> </ReportData> |
Syntax | Return Type | Description | Example |
---|---|---|---|
|
boolean | Converts the argument to a Boolean. |
boolean(1) returns True. boolean(0) returns False. |
|
boolean | Returns False. | false() returns False. |
|
boolean | Returns true if the xml:lang attribute of the context node is the same as the argument string. | count(lang("en-US")) returns 1 if the context node has an xml:lang attribute of "en-US". |
|
boolean | Returns True if the argument is false, otherwise, False. | not("true") returns False. |
|
boolean | Converts the argument to a Boolean. If the argument is a node-set, then it takes the text of the first node and converts it to a Boolean value. It returns True if the text is ‘true’ or ‘1’; Otherwise, it returns False. | to-boolean("true") returns True. |
|
boolean | Returns True. | true() returns True. |
Conditional functions
Syntax | Return Type | Description | Example |
---|---|---|---|
|
object | Returns one of two values (the second and the third parameter), depending on whether the Boolean expression (the first parameter) evaluates to true or false. | iif(1 > 0, "red", "blue") returns the string "red". |
|
object | Accepts a list of parameters and returns the first value from the list that is not an empty string nor empty node set. | coalesce("", 1, "bar") returns the string "1". |
Context functions
Sample XML fragment
That is used to demonstrate how the Context functions work - in the Example column in the below table.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<dsp:dataSection dsp:type="GeneralData"> <dsp:data> <GeneralData> <CurrentCompany CompanyId="usmf"> </CurrentCompany> </GeneralData> </dsp:data> </dsp:dataSection> <dsp:dataSection dsp:type="MainData"> <dsp:data> <ReportData> <SalesInvoiceLines LineAmount="1920.0000000000" Name="Mid-Range Speaker"> <PackingSlip ShowCustPackingSlipTrans="false" /> </SalesInvoiceLines> <SalesInvoiceLines LineAmount="80.0000000000" Name="Low-Range Speaker"> <PackingSlip ShowCustPackingSlipTrans="true" /> </SalesInvoiceLines> </ReportData> </dsp:data> </dsp:dataSection> |
Syntax | Return Type | Description | Example |
---|---|---|---|
|
node-set | Returns the current XML node that is the current data context item. | current() returns the current <SalesInvoiceLines> node. |
|
node-set | Returns the node-set which is the resulting item collection of the current directly or indirectly wrapping List or Group tagging element. | current-collection() returns the current <SalesInvoiceLines> node. |
|
node-set | Returns the 1-based index of the current data context item in the resulting item collection. The resulting item collection is the product of a List or Group tagging element. | current-index() returns 1 or 2. |
|
node-set | Returns the root XML element of the specified data source. | data-source('GeneralData') returns <GeneralData> root element. |
|
node-set | Returns all groups created by the last processed Group tagging element. | last-processed-group-element-result(SalesInvoiceLines)[1]/@Name returns "Low-Range Speaker". |
|
- | Returns the value of the specified Var tagging element. The argument must be the name of an existing Var tagging element. | We create Var-Tagging element with name Counter and value 0. Then, when we use var-element-value("Counter"), it returns 0. |
Date-Time functions
Syntax | Return Type | Description | Example |
---|---|---|---|
|
date-time | Returns a date-time value that adds the specified number of days (second parameter) to the given date-time value (first parameter). | date-time-add-days("2023-08-20T15:20:00", 3) returns the date-time value "2023-08-23T15:20:00". |
|
date-time | Returns a date-time value that adds the specified number of months (second parameter) to the given date-time value (first parameter). | date-time-add-months("2023-08-20T15:20:00", 1) returns the date-time value "2023-09-20T15:20:00". |
|
date-time | Returns a date-time value that adds the specified number of years (second parameter) to the given date-time value (first parameter). | date-time-add-years("2023-08-20T15:20:00", 1) returns the date-time value "2024-08-20T15:20:00". |
|
number | Returns the day component of the given date-time. | day("2023-08-20T15:20:00") returns the number 20. |
|
number | Returns the hour component of the given date-time. | hour("2023-08-20T15:20:00") returns the number 15. |
|
number | Returns the millisecond component of the given date-time. | millisecond("2023-08-20T15:20:00.123") returns the number 123. |
|
number | Returns the minute component of the given date-time. | minute("2023-08-20T15:20:00") returns the number 20. |
|
number | Returns the month component of the given date-time. | month("2023-08-20T15:20:00") returns the number 8. |
|
date-time | Returns a date-time that is the current date and time on this computer, expressed as the local time. | now() returns the current date and time in the local time zone. |
|
number | Returns the second component of the given date-time. | second("2023-08-20T15:20:00") returns the number 0. |
|
date-time | Converts the given date-time formatted string to a date-time value. | to-date-time("2023-08-20T15:20:35") returns the date-time value "2023-08-20T15:20:35". |
|
number | Returns the year component of the given date-time. | year("2023-08-20T15:20:00") returns the number 2023. |
Misc functions
Syntax | Return Type | Description | Example |
---|---|---|---|
|
string | Returns a label translation for the provided label code. | label("@SYS80991") returns Name. |
|
string | Loads the resource from the specified URL and returns the binary data encoded as Base 64 string. The first parameter accepts the resource URL. The second (optional) parameter accepts a boolean value indicating whether an error due to a failed operation should be suppressed ('false' by default). |
load-binary("https:// |
|
string | Loads the text file/resource from the specified URL and returns the data as string. The first parameter accepts the resource URL. The second (optional) parameter accepts a boolean value indicating whether an error due to a failed operation should be suppressed ('false' by default). |
load-text("https:// |
Node-Set functions
Sample XML fragment
That is used to demonstrate how the Node-Set functions work - in the Example column in the below table.
1 2 3 4 5 6 7 8 |
<ReportData xmlns="https://ax.docentric.com/"> <SalesInvoiceLines LineAmount="1920.0000000000" Name="Mid-Range Speaker" id="1"> <PackingSlip PackingSlip="" ShowCustPackingSlipTrans="false" /> </SalesInvoiceLines> <SalesInvoiceLines LineAmount="80.0000000000" Name="Low-Range Speaker" id="2"> <PackingSlip PackingSlip="" ShowCustPackingSlipTrans="true" /> </SalesInvoiceLines> </ReportData> |
Syntax | Return Type | Description | Example |
---|---|---|---|
|
number | Returns the number of nodes in the node-set argument. | count(SalesInvoiceLines) returns 2. |
|
node-set | Selects elements by their unique ID. | count(SalesInvoiceLines[id(1)]) returns 1. |
|
number | Reports the one-based index of the first occurrence of the specified reference node (second parameter) in the source node set (first parameter). | index-of(SalesInvoiceLines, PackingSlip) returns -1. |
|
number | Returns a number equal to context size of the expression evaluation context. | last() returns 2. |
|
string | Returns the local part of the expanded name of the node in the node-set argument that is first in document order. | local-name(SalesInvoiceLines) returns SalesInvoiceLines. |
|
string | Returns a string containing a QName representing the expanded name of the node in the node-set argument that is first in document order. | name(SalesInvoiceLines) returns SalesInvoiceLines. |
|
node-set | Returns a string collection containing a QName representing the expanded name of all the nodes in the given node-set argument. | names(SalesInvoiceLines) returns SalesInvoiceLinesSalesInvoiceLines. |
|
string | Returns the namespace Uniform Resource Identifier (URI) of the expanded name of the node in the node-set argument that is first in document order. | namespace-uri(ReportData) returns https://ax.docentric.com |
|
number | Returns the index number of the node within the parent. | position() returns 1. |
|
node-set | Skips the specified number (second parameter) of XML nodes in the given node set (first parameter) and then returns the remaining nodes. | skip(SalesInvoiceLines, 1) returns <SalesInvoiceLines LineAmount="80.0000000000" Name="Low-Range Speaker"></SalesInvoiceLines>. |
|
node-set | Returns only the first specified number (second parameter) of XML nodes in the given node set (first parameter). | take(SalesInvoiceLines, 1) returns <SalesInvoiceLines LineAmount="1920.0000000000" Name="Mid-Range Speaker"></SalesInvoiceLines>. |
Number functions
That is used to demonstrate how the Number functions work - in the Example column in the below table.
1 2 3 4 5 |
<ReportData> <SalesInvoiceLines LineAmount="100.0000000000" /> <SalesInvoiceLines LineAmount="200.0000000000" /> <SalesInvoiceLines LineAmount="300.0000000000" /> </ReportData> |
Syntax | Return Type | Description | Example |
---|---|---|---|
|
number | Returns the absolute value of a specified number. | abs(-10) returns 10. |
|
number | Returns the smallest integer that is not less than the argument. | ceiling(3.14) returns 4. |
|
number | Returns the largest integer that is not greater than the argument. | floor(3.14) returns 3. |
|
number | Converts the argument to a number. | number("123") returns the number 123. |
|
number | Returns an integer closest in value to the argument. | round(3.14) returns 3. |
|
number | Rounds the given decimal value to the specified number of fractional digits. | round-number(3.14159, 2) returns 3.14. |
|
number | Returns the sum of all nodes in the node-set. Each node is first converted to a number value before summing. |
sum(SalesInvoiceLines/ NOTE: To display the resulting number in a particular format (e.g. 600.00), it should be formatted by applying Format String (e.g. "n2"). |
String functions
Sample XML fragment
That is used to demonstrate how the String functions work - in the Example column in the below table.
1 2 3 4 |
<ReportData> <SalesInvoiceLines Name="Mid-Range Speaker" /> <SalesInvoiceLines Name="Low-Range Speaker" /> </ReportData> |
Syntax | Return Type | Description | Example |
---|---|---|---|
|
string | Returns a carriage return character. | $cr. |
|
string | Returns a new line feed. | $lf. |
|
string | Returns a new line string. | $new-line. |
|
string | Returns a tab character. | $tab. |
|
string | Returns the character from the provided ASCII number. | char(65) returns the character A. |
|
string | Returns the concatenation of the arguments. | concat("Hello", " ", "World") returns the string Hello World. |
|
boolean | Returns true if the first argument string contains the second argument string; otherwise returns false. | contains("Hello World", "World") returns true. |
|
string | Converts the numeric or date-time value to its equivalent string representation, using the specified format. This function accepts 3 parameters. The first one is a number or date-time value to format. The second parameter is a format string. The third parameter is optional and accepts a value representing a culture name (e.g., 'en-US') to be used for the format operation instead of the currently set culture. | format (1234567890, "###,###,###,###") returns the string "1,234,567,890". |
|
string | Encodes the given string by using the UTF-8 encoding and returns the binary result in the form of a Base 64 string. | get-string-binary("Hello World") returns the Base 64 string SGVsbG8gV29ybGQ=. |
|
string | Returns the given string converted to lowercase. | lower-case("Hello World") returns the string "hello world". |
|
string | Returns the argument string with the white space stripped. | normalize-space(" Hello World ") returns the string "Hello World". |
|
string | Replaces parts of the input string (the first parameter) with the replacement string (the third parameter) that match regular expression pattern. | replace("Hello World", "World", "Universe") returns the string "Hello Universe". |
|
boolean | Returns true if the first argument string starts with the second argument string; otherwise returns false. | starts-with("Hello", "He") returns True. |
|
string | Converts an object to a string. | string(123) returns "123". |
|
number | Searches the input string (first parameter) for an occurrence of the search string (second parameter). It returns the character index of the first occurrence of the search string. | string-find("Hello World", "e") returns 2. |
|
string | Returns the string containing the concatenated strings of the given nodes delimited by the string specified by the second parameter. The third parameter is optional and specifies the string which acts as the last delimiter. | string-join(SalesInvoiceLines/@Name, " - ") returns "Mid-Range Speaker - Low-Range Speaker". |
|
number | Returns the number of characters in the string. | string-length("Hello World") returns 11. |
|
node-set | Returns a node set of strings that contains the substrings of the input string (first parameter) delimited by the specified string (third parameter). If the Remove Empty Entries flag (second parameter) is set to True, then all empty strings will be removed from the result. | string-split("Contoso Entertainment System USA", true(), " ") returns "ContosoEntertainmentSystemUSA". |
|
string | Returns the substring of the first argument starting at the position specified in the second argument and the length specified in the third argument. | substring("Hello World", 1, 5) returns "Hello". |
|
string | Returns the substring of the first argument string that follows the first occurrence of the second argument string in the first argument string. | substring-after("Hello World", " ") returns "World". |
|
string | Returns the substring of the first argument string that precedes the first occurrence of the second argument string in the first argument string. | substring-before("Hello World", " ") returns "Hello". |
|
string | Returns the first argument string with occurrences of characters in the second argument string replaced by the character at the corresponding position in the third argument string. | translate("Hello World","o","M") returns "HellM WMrld". |
|
string | Removes whitespaces on the left and the right side of the input string and returns the remaining string. If the input string is not provided, the current XML node is used as the input. | trim(" Hello World ") returns "Hello World". |
|
string | Returns the given string converted to uppercase. | upper-case("Hello World") returns "HELLO WORLD". |
See also
XPath Expressions Overview >>
XPath Selecting and Filtering Nodes >>
XPath Operators >>