Standard functions for ION mappings

You can use several standard functions in ION mappings.

Comparison

This table shows the comparison functions:

Function Description Example
Position Returns the index position of the node that is currently being processed. Example:
//book[position()<=3] 

Result: Selects the first three book elements.

Equals Returns true if param1 and param2 are deep-equal to each other. Otherwise the function returns false.
Not-Equals Returns true if param1 and param2 are not deep-equal to each other. Otherwise the function returns false.

Constant

This table shows the constant functions:

Function Description
String Returns a string constant defined by the user.
Number Returns a value constant defined by the user.

Data type casting

This table shows the data type casting functions:

Function Description Example
Cast to string Returns an entry as a string.
Cast to Normalized String Returns an entry as a normalized string. That is, Whitespace-replaced strings.
Cast to Date and Time Returns an entry as Date and time.
Cast to Date Returns an entry as Date.
Cast to Time Returns an entry as Time.
Cast to Decimal Returns an entry as Decimal.
Cast to Integer Returns an entry as Integer.
Cast to Double Returns an entry as Double.
Cast to Float Returns an entry as Float.
Cast to Boolean Returns an entry as Boolean.
Cast to gYearMonth Returns an entry as gYearMonth. That is, a period of one month. Valid values include "2001-10", "2001-10+02:00", "2001-10Z", "2001-10+00:00", "-2001-10", or "-20000-04".
Cast to gYear Returns an entry as gYear. That is, a period of one year. Valid values include "2001", "2001+02:00", "2001Z", "2001+00:00", "-2001", and "-20000".
Cast to gMonthDay Returns an entry as gMonthDay. That is, a recurring period of time: yearly day. Valid values are "--05-01", "--11-01Z", "--11-01+02:00", "--11-01-04:00", "--11-15", and "--02-29".
Cast to gDay Returns an entry as gDay. That is, a recurring period of time: monthly day. Valid values include "---01", "---01Z", "---01+02:00", "---01-04:00", "---15", and "---31".
Cast to gMonth Returns an entry as gMonth. That is, a recurring period of time: yearly month. Valid values include "--05", "--11Z", "--11+02:00", "--11-04:00", and "--02".
Cast to Long Returns an entry as Long.
Cast to Int Returns an entry as Int.
Cast to Short Returns an entry as Short.
Cast to Byte Returns an entry as Byte.
Cast to Token Returns an entry as Token.
Cast to Language Returns an entry as Language.

Date and time

This table shows the date and time functions:
Function Description
Adjust Date and Time to Time Zone If the timezone argument is empty, this function returns a dateTime without timezone. Otherwise, this function returns a dateTime with the timezone.
Adjust Date to Time Zone If the timezone argument is empty, this function returns a date without timezone. Otherwise, this function returns a date with the timezone.
Adjust Time to Time Zone If the timezone argument is empty, this function returns a time without timezone. Otherwise, this function returns a time with the timezone.
Current Date and Time Returns the current dateTime, with the timezone.
Current Date Returns the current date, with the timezone..
Current Time Returns the current time, with the timezone.
Format Date and Time - date:format-date-time This function formats a date and time according to a pattern. The first argument specifies the date and time to be formatted. The second argument is a string that specifies the format pattern that is used to format the date-time.
Format Date - date:format-date This function formats a date according to a pattern. The first argument specifies the date to be formatted. The second argument is a string that specifies the format pattern that is used to format the date. For example: [M01]/[D01]/[Y0001]') = 09/19/2013
Format Time - date:format-time This function formats a time according to a pattern. The first argument specifies the time to be formatted. The second argument is a string that specifies the format pattern that is used to format the time. For example: [H01]:[m01] [z]') = 09:26 GMT+10

Logical

This table shows the logical functions:

Function Description Example
Choose Used to choose one of several alternative outputs.
<xsl:choose>
    <xsl:when test="@cat='F'">Fiction</xsl:when>
    <xsl:when test="@cat='C'">Crime</xsl:when>
    <xsl:when test="@cat='R'">Reference</xsl:when>
    <xsl:otherwise>General</xsl:otherwise>
</xsl:choose>

The first xsl:when element whose condition matches the current element in the source document is expanded. The others are ignored.

If The function takes a mandatory test attribute, whose value is a boolean expression. The contents of the xsl:if element are expanded only if the expression is true. Includes a hyperlink in the output only if the current element has a preface attribute:
<xsl:if test="@preface">
    <a href="preface.html">Preface</a>
</xsl:if>
Matches Returns true if the string argument matches the pattern. Otherwise the function returns false. Example:
matches("Merano", "ran")

Result: true

Not The argument is first reduced to a boolean value by applying the boolean() function.

Returns true if the boolean value is false. Returns false if the boolean value is true.

TRUE Returns the boolean value true.
FALSE Returns the boolean value false.

Math

This table shows the math functions:

Function Description Example
Highest* Returns the nodes from the node set whose values are the maximum values in the node set. The highest* function inserts elements as an array and returns an array of elements.
Lowest* Returns the nodes from the node set whose values are the minimum values in the node set. The lowest* function inserts elements as an array and returns an array of elements.
Maximum* Returns the argument that is greater than the others. The maximum* function inserts elements as an array and returns one value. Example:
max((1,2,3))

Result: 3

Minimum* Returns the argument that is less than the others. The minimum* function inserts elements as an array and returns one value. " " Example:
min((1,2,3))

Result: 1

Sum* Returns the sum of the numeric values of nodes in the specified node­set. The sum* function inserts elements as an array and returns one value.
Add Returns the sum of entry values.
Subtract Returns the difference of entry values.
Multiply Returns the multiplication product of entry values.
Divide Returns the quotient of entry values.
String Returns a string equivalent of the argument. The argument can be a number, boolean, or node­set. Example:
string(314)

Result: "314"

Concatenate Returns the result of concatenation of the specified strings. Example:
concat('XPath ','is ','FUN!') 

Result: 'XPath is FUN!'

Join strings* Returns a string that is created by concatenating the string arguments and using the sep argument as the separator. The join strings* function inserts separate strings as an array, uses the separator as a single string, and returns one string. Example:
string­join(('We', 'are', 'having', 'fun!'), ' ')

Result: 'We are having fun!'

Length of string 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

Substring Returns the substring from the start position to the specified length. Index of the first character is 1. If length is not specified, the function returns the substring from the start position to the end. Example:
substring('Beatles',1,4)

Result: 'Beat'

Example:

substring('Beatles',2)

Result: 'eatles'

Substring after Returns the part of string 1 from where string 2 occurs in it until the end. Example:
substring­after('12/10','/')

Result: '10'

Substring before Returns the part of string 1 from the start until string 2 occurs in it.
Tokenize* Inserts two elements and returns elements as an array.
tokenize("XPath is fun", "\s+")

Result: ("XPath", "is", "fun")

Normalize spaces Removes extra whitespace from its argument string. The argument string, with whitespace removed as follows:
  • All leading whitespace is removed.
  • All trailing whitespace is removed.
  • Within the string, any sequence of whitespace characters is replaced with a single space.

Function templates

This table shows the function templates:

Function template Description Example
create-property Returns a user-defined function that provides a property.
<xsl:element name=""Property"">
 <xsl:element name=""NameValue"">
  <xsl:attribute name=""name"">
   <xsl:value-of select=""$name""/>
  </xsl:attribute>
  <xsl:attribute name=""type"">
   <xsl:value-of select=""$type""/>
  </xsl:attribute>
  <xsl:value-of select=""$element""/>
 </xsl:element>
</xsl:element>
fill-property Returns a user-defined function for filling a property.
<xsl:element name=""NameValue"">
 <xsl:attribute name=""name"">
  <xsl:value-of select=""$name""/>
 </xsl:attribute>
 <xsl:attribute name=""type"">
  <xsl:value-of select=""$type""/>
 </xsl:attribute>
 <xsl:value-of select=""$element""/>
</xsl:element>
get-first-item Returns a user-defined function that provides the first item.
<xsl:copy-of select="$input-list[1]"  copy-namespaces="no" />
get-first-value Returns a user-defined function that provides the first value.
<xsl:value-of select="$input-list[1]"/>
custom-function Returns a user-defined function with blank function body.
keep-date-reset-time Returns a datetime string where the original input time is replaced by "00:00:00Z". "2016-11-16T19:48:39.280Z" is converted into “2016-11-16T00:00:00Z”.
keep-date-set-current-time Returns a datetime string where the original input time is replaced by the current time.
create-child-element Creates a child element of the element to which the function is applied.
<xsl:element name="{$child-element-name}">
 <xsl:value-of select="$child-element-value"/>
 </xsl:element> 
create-child-element-with-attr Creates a child element, with an attribute, of the element to which the function is applied.
<xsl:element name="$child-element-name">
 <xsl:attribute name="$attribute-name">
 <xsl:value-of select="$attribute-value"/>
 </xsl:attribute>
 <xsl:value-of select="$child-element-value"/>
 </xsl:element> 
get-elem-by-attr-name-and-value Search for an element that has a specific attribute name and value:
  • If the element has the searched attribute name and value, return the element.
  • If the element does not have the searched attribute name and value, return null.

The first parameter always must be the actual source element, that is, node. This parameter cannot be a constant; it requires more than just an element name.

convert-numbers-to-words Returns numeric values to text format displaying them as words. Upper limit is the billion and floats are rounded up or down accordingly <xsl: number value="54" format="Ww" lang="en"/>
Note: All of the above functions, except UDF, are not editable.

User-defined functions

This table shows the user-defined functions:

Function Description
function name Returns a previously stored user-defined function.