Start Here   Setup   Adapters   Studio   Server   Monitor   Mapping   Scripting   Samples   Index 

XML Functions

 Data Mapping    Linking Events    Linking Resources    Linking Tasks    XML Templates    XML Elements    XML Functions  

What are XML Functions?

The XSLT language includes over 100 built-in functions for string values, numeric values, date and time comparison, node and QName manipulation, sequence manipulation, Boolean values, and more.

For more information on the XSLT Specification, see http://www.w3.org/TR/xslt20

For more information on XPath Functions, see http://www.w3.org/TR/xpath-functions

XML Functions by Category

Accessor Functions

Function Description
base-uri()
base-uri(node)
Returns the value of the base-uri property of the current or specified node
data(item.item,...) Takes a sequence of items and returns a sequence of atomic values
document-uri(node) Returns the value of the document-uri property for the specified node
nilled(node) Returns a Boolean value indicating whether the argument node is nilled
node-name(node) Returns the node-name of the argument node
system-property(string)

The system-property() function returns the value of the system property specified by the name. System properties in the XSLT namespace:

  • xsl:version - The version of XSLT implemented by the processor
  • xsl:vendor - The vendor of the XSLT processor
  • xsl:vendor-url - The URL identifying the vendor of the XSLT processor

Error and Trace Functions

error()
error(error)
error(error,description)
error(error,description,error-object)
Example: error(QName('http://example.com/test', 'err:toohigh'), 'Error: Price is too high')

Result: Returns http://example.com/test#toohigh and the string "Error: Price is too high" to the external processing environment

trace(value,label) Used to debug queries

Numeric Functions

number(arg) Returns the numeric value of the argument. The argument could be a boolean, string, or node-set

Example: number('100')
Result: 100

abs(num) Returns the absolute value of the argument

Example: abs(3.14)
Result: 3.14

Example: abs(-3.14)
Result: 3.14

ceiling(num) Returns the smallest integer that is greater than the number argument

Example: ceiling(3.14)
Result: 4

floor(num) Returns the largest integer that is not greater than the number argument

Example: floor(3.14)
Result: 3

format-number(number,format,[decimalformat])

The format-number() function is used to convert a number into a string. Here are some of the characters used in the formatting pattern:

  • # (Denotes a digit. Example: ####)
  • 0 (Denotes leading and following zeros. Example: 0000.00)
  • . (The position of the decimal point Example: ###.##)
  • , (The group separator for thousands. Example: ###,###.##)
  • % (Displays the number as a percentage. Example: ##%)
  • ; (Pattern separator. The first pattern will be used for positive numbers and the second for negative numbers)
round(num) Rounds the number argument to the nearest integer

Example: round(3.14)
Result: 3

round-half-to-even() Example: round-half-to-even(0.5)
Result: 0

Example: round-half-to-even(1.5)
Result: 2

Example: round-half-to-even(2.5)
Result: 2

String Functions

string(arg) Returns the string value of the argument. The argument could be a number, boolean, or node-set

Example: string(314)
Result: "314"

codepoints-to-string(int,int,...) Returns a string from a sequence of code points

Example: codepoints-to-string(84, 104, 233, 114, 232, 115, 101)
Result: 'Thérèse'

string-to-codepoints(string) Returns a sequence of code points from a string

Example: string-to-codepoints("Thérèse")
Result: 84, 104, 233, 114, 232, 115, 101

codepoint-equal(comp1,comp2) Returns true if the value of comp1 is equal to the value of comp2, according to the Unicode code point collation (http://www.w3.org/2005/02/xpath-functions/collation/codepoint), otherwise it returns false
compare(comp1,comp2)
compare(comp1,comp2,collation)
Returns -1 if comp1 is less than comp2, 0 if comp1 is equal to comp2, or 1 if comp1 is greater than comp2 (according to the rules of the collation that is used)

Example: compare('ghi', 'ghi')
Result: 0

concat(string,string,...) Returns the concatenation of the strings

Example: concat('XPath ','is ','FUN!')
Result: 'XPath is FUN!'

string-join((string,string,...),sep) Returns a string created by concatenating the string arguments and using the sep argument as the separator

Example: string-join(('We', 'are', 'having', 'fun!'), ' ')
Result: ' We are having fun! '

Example: string-join(('We', 'are', 'having', 'fun!'))
Result: 'Wearehavingfun!'

Example:string-join((), 'sep')
Result: ''

substring(string,start,len)
substring(string,start)
Returns the substring from the start position to the specified length. Index of the first character is 1. If length is omitted it returns the substring from the start position to the end

Example: substring('Beatles',1,4)
Result: 'Beat'

Example: substring('Beatles',2)
Result: 'eatles'

string-length(string)
string-length()
Returns the length of the specified string. If there is no string argument it returns the length of the string value of the current node

Example: string-length('Beatles')
Result: 7

normalize-space(string)
normalize-space()
Removes leading and trailing spaces from the specified string, and replaces all internal sequences of white space with one and returns the result. If there is no string argument it does the same on the current node

Example: normalize-space(' The   XML ')
Result: 'The XML'

upper-case(string) Converts the string argument to upper-case

Example: upper-case('The XML')
Result: 'THE XML'

lower-case(string) Converts the string argument to lower-case

Example: lower-case('The XML')
Result: 'the xml'

translate(string1,string2,string3) Converts string1 by replacing the characters in string2 with the characters in string3

Example: translate('12:30','30','45')
Result: '12:45'

Example: translate('12:30','03','54')
Result: '12:45'

Example: translate('12:30','0123','abcd')
Result: 'bc:da'

escape-html-uri(stringURI,esc-res) Example: escape-html-uri("http://example.com/test#car", true())
Result: "http%3A%2F%2Fexample.com%2Ftest#car"

Example: escape-html-uri("http://example.com/test#car", false())
Result: "http://example.com/test#car"

Example: escape-html-uri ("http://example.com/~bébé", false())
Result: "http://example.com/~b%C3%A9b%C3%A9"

contains(string1,string2) Returns true if string1 contains string2, otherwise it returns false

Example: contains('XML','XM')
Result: true

starts-with(string1,string2) Returns true if string1 starts with string2, otherwise it returns false

Example: starts-with('XML','X')
Result: true

ends-with(string1,string2) Returns true if string1 ends with string2, otherwise it returns false

Example: ends-with('XML','X')
Result: false

substring-before(string1,string2) Returns the start of string1 before string2 occurs in it

Example: substring-before('12/10','/')
Result: '12'

substring-after(string1,string2) Returns the remainder of string1 after string2 occurs in it

Example: substring-after('12/10','/')
Result: '10'

matches(string,pattern) Returns true if the string argument matches the pattern, otherwise, it returns false

Example: matches("Merano", "ran")
Result: true

replace(string,pattern,replace) Returns a string that is created by replacing the given pattern with the replace argument

Example: replace("Bella Italia", "l", "*")
Result: 'Be**a Ita*ia'

Example: replace("Bella Italia", "l", "")
Result: 'Bea Itaia'
tokenize(string,pattern) Example: tokenize("XPath is fun", "\s+")
Result: ("XPath", "is", "fun")

Functions for any URI

resolve-uri(relative,base)  
unparsed-entity-uri(string)

The unparsed-entity-uri() function returns the URI of an unparsed entity. The name of the entity must match the passed argument. If there is no such entity an empty string is returned.

If the DTD contains the following declaration:

<!ENTITY pic SYSTEM "http://www.w3schools.com/picture.jpg" NDATA JPEG>

the following expression:

unparsed-entity-uri('pic')

will return the URI for the file "picture.jpg".

Boolean Functions

boolean(arg) Returns a boolean value for a number, string, or node-set
element-available(string)

The element-available() function returns a Boolean value that indicates whether the element specified is supported by the XSLT processor.

function-available(string)

The function-available() function returns a Boolean value that indicates whether the function specified is supported by the XSLT processor.

not(arg) The argument is first reduced to a boolean value by applying the boolean() function. Returns true if the boolean value is false, and false if the boolean value is true

Example: not(true())
Result: false

true() Returns the boolean value true

Example: true()
Result: true

false() Returns the boolean value false

Example: false()
Result: false

Date and Time Functions

dateTime(date,time) Converts the arguments to a date and a time
years-from-duration(datetimedur) Returns an integer that represents the years component in the canonical lexical representation of the value of the argument
months-from-duration(datetimedur) Returns an integer that represents the months component in the canonical lexical representation of the value of the argument
days-from-duration(datetimedur) Returns an integer that represents the days component in the canonical lexical representation of the value of the argument
hours-from-duration(datetimedur) Returns an integer that represents the hours component in the canonical lexical representation of the value of the argument
minutes-from-duration(datetimedur) Returns an integer that represents the minutes component in the canonical lexical representation of the value of the argument
seconds-from-duration(datetimedur) Returns a decimal that represents the seconds component in the canonical lexical representation of the value of the argument
year-from-dateTime(datetime) Returns an integer that represents the year component in the localized value of the argument

Example: year-from-dateTime(xs:dateTime("2005-01-10T12:30-04:10"))
Result: 2005

month-from-dateTime(datetime) Returns an integer that represents the month component in the localized value of the argument

Example: month-from-dateTime(xs:dateTime("2005-01-10T12:30-04:10"))
Result: 01

day-from-dateTime(datetime) Returns an integer that represents the day component in the localized value of the argument

Example: day-from-dateTime(xs:dateTime("2005-01-10T12:30-04:10"))
Result: 10

hours-from-dateTime(datetime) Returns an integer that represents the hours component in the localized value of the argument

Example: hours-from-dateTime(xs:dateTime("2005-01-10T12:30-04:10"))
Result: 12

minutes-from-dateTime(datetime) Returns an integer that represents the minutes component in the localized value of the argument

Example: minutes-from-dateTime(xs:dateTime("2005-01-10T12:30-04:10"))
Result: 30

seconds-from-dateTime(datetime) Returns a decimal that represents the seconds component in the localized value of the argument

Example: seconds-from-dateTime(xs:dateTime("2005-01-10T12:30:00-04:10"))
Result: 0

timezone-from-dateTime(datetime) Returns the time zone component of the argument if any
year-from-date(date) Returns an integer that represents the year in the localized value of the argument

Example: year-from-date(xs:date("2005-04-23"))
Result: 2005

month-from-date(date) Returns an integer that represents the month in the localized value of the argument

Example: month-from-date(xs:date("2005-04-23"))
Result: 4

day-from-date(date) Returns an integer that represents the day in the localized value of the argument

Example: day-from-date(xs:date("2005-04-23"))
Result: 23

timezone-from-date(date) Returns the time zone component of the argument if any
hours-from-time(time) Returns an integer that represents the hours component in the localized value of the argument

Example: hours-from-time(xs:time("10:22:00"))
Result: 10

minutes-from-time(time) Returns an integer that represents the minutes component in the localized value of the argument

Example: minutes-from-time(xs:time("10:22:00"))
Result: 22

seconds-from-time(time) Returns an integer that represents the seconds component in the localized value of the argument

Example: seconds-from-time(xs:time("10:22:00"))
Result: 0

timezone-from-time(time) Returns the time zone component of the argument if any

QName Functions

QName()  
local-name-from-QName()  
namespace-uri-from-QName()  
namespace-uri-for-prefix()  
in-scope-prefixes()  
resolve-QName()  

Node Functions

current()

Returns a node-set that contains only the current node. Usually the current node and the context node are the same.

<xsl:value-of select="current()"/>
is equal to
<xsl:value-of select="."/>

document(object,node-set)

The document() function is used to access nodes in an external XML document. The external XML document must be valid and parsable.

One way to use this function is to look up data in an external document. For example we want to find the Celsius value from a Fahrenheit value and we refer to a document that contains some pre-computed results:

<xsl:value-of select="document('celsius.xml')/celsius/result[@value=$value]"/>

generate-id(node-set)

The generate-id() function returns a string value that uniquely identifies a specified node. If the node-set specified is empty, an empty string is returned. If you omit the node-set parameter, it defaults to the current node.

key(keyName, keyNode) The key() function returns a node-set from the document, using the index specified by an <xsl:key> element.
name()
name(nodeset)
Returns the name of the current node or the first node in the specified node set
local-name()
local-name(nodeset)
Returns the name of the current node or the first node in the specified node set - without the namespace prefix
namespace-uri()
namespace-uri(nodeset)
Returns the namespace URI of the current node or the first node in the specified node set
lang(lang) Returns true if the language of the current node matches the language of the specified language

Example: Lang("en") is true for
<p xml:lang="en">...</p>

Example: Lang("de") is false for
<p xml:lang="en">...</p>

root()
root(node)
Returns the root of the tree to which the current node or the specified belongs. This will usually be a document node

Sequence Functions

General Functions on Sequences

index-of((item,item,...),searchitem) Returns the positions within the sequence of items that are equal to the searchitem argument

Example: index-of ((15, 40, 25, 40, 10), 40)
Result: (2, 4)

Example: index-of (("a", "dog", "and", "a", "duck"), "a")
Result (1, 4)

Example: index-of ((15, 40, 25, 40, 10), 18)
Result: ()

remove((item,item,...),position) Returns a new sequence constructed from the value of the item arguments - with the item specified by the position argument removed

Example: remove(("ab", "cd", "ef"), 0)
Result: ("ab", "cd", "ef")

Example: remove(("ab", "cd", "ef"), 1)
Result: ("cd", "ef")

Example: remove(("ab", "cd", "ef"), 4)
Result: ("ab", "cd", "ef")

empty(item,item,...) Returns true if the value of the arguments IS an empty sequence, otherwise it returns false

Example: empty(remove(("ab", "cd"), 1))
Result: false

exists(item,item,...) Returns true if the value of the arguments IS NOT an empty sequence, otherwise it returns false

Example: exists(remove(("ab"), 1))
Result: false

distinct-values((item,item,...),collation) Returns only distinct (different) values

Example: distinct-values((1, 2, 3, 1, 2))
Result: (1, 2, 3)

insert-before((item,item,...),pos,inserts) Returns a new sequence constructed from the value of the item arguments - with the value of the inserts argument inserted in the position specified by the pos argument

Example: insert-before(("ab", "cd"), 0, "gh")
Result: ("gh", "ab", "cd")

Example: insert-before(("ab", "cd"), 1, "gh")
Result: ("gh", "ab", "cd")

Example: insert-before(("ab", "cd"), 2, "gh")
Result: ("ab", "gh", "cd")

Example: insert-before(("ab", "cd"), 5, "gh")
Result: ("ab", "cd", "gh")

reverse((item,item,...)) Returns the reversed order of the items specified

Example: reverse(("ab", "cd", "ef"))
Result: ("ef", "cd", "ab")

Example: reverse(("ab"))
Result: ("ab")

subsequence((item,item,...),start,len) Returns a sequence of items from the position specified by the start argument and continuing for the number of items specified by the len argument. The first item is located at position 1

Example: subsequence(($item1, $item2, $item3,...), 3)
Result: ($item3, ...)

Example: subsequence(($item1, $item2, $item3, ...), 2, 2)
Result: ($item2, $item3)

unordered((item,item,...)) Returns the items in an implementation dependent order

Functions That Test the Cardinality of Sequences

zero-or-one(item,item,...) Returns the argument if it contains zero or one items, otherwise it raises an error
one-or-more(item,item,...) Returns the argument if it contains one or more items, otherwise it raises an error
exactly-one(item,item,...) Returns the argument if it contains exactly one item, otherwise it raises an error

Equals, Union, Intersection and Except

Name Description
deep-equal(param1,param2,collation) Returns true if param1 and param2 are deep-equal to each other, otherwise it returns false

Aggregate Functions

count((item,item,...)) Returns the count of nodes
avg((arg,arg,...)) Returns the average of the argument values

Example: avg((1,2,3))
Result: 2

max((arg,arg,...)) Returns the argument that is greater than the others

Example: max((1,2,3))
Result: 3

Example: max(('a', 'k'))
Result: 'k'

min((arg,arg,...)) Returns the argument that is less than the others

Example: min((1,2,3))
Result: 1

Example: min(('a', 'k'))
Result: 'a'

sum(arg,arg,...) Returns the sum of the numeric value of each node in the specified node-set

Functions that Generate Sequences

id((string,string,...),node) Returns a sequence of element nodes that have an ID value equal to the value of one or more of the values specified in the string argument
idref((string,string,...),node) Returns a sequence of element or attribute nodes that have an IDREF value equal to the value of one or more of the values specified in the string argument
doc(URI)  
doc-available(URI) Returns true if the doc() function returns a document node, otherwise it returns false
collection()
collection(string)
 

Context Functions

position() Returns the index position of the node that is currently being processed

Example: //book[position()<=3]
Result: Selects the first three book elements

last() Returns the number of items in the processed node list

Example: //book[last()]
Result: Selects the last book element

current-dateTime() Returns the current dateTime (with timezone)
current-date() Returns the current date (with timezone)
current-time() Returns the current time (with timezone)
implicit-timezone() Returns the value of the implicit timezone
default-collation() Returns the value of the default collation
static-base-uri() Returns the value of the base-uri

Next: Data Scripting

 Start Here   Setup   Adapters   Studio   Server   Monitor   Mapping   Scripting   Samples   Index 

ActiveLink Help - Version 4.1.1
© 2006 ActiveCore Technologies Inc.
activelink@activecore.com