These functions perform arithmetic calculations and manipulate numerical values.
number()
Converts a value to a number.
- <xsl:value-of select="number('123.45')"/>
Output: 123.45
sum()
Calculates the sum of a node set.
- <xsl:value-of select="sum(/price)"/>
Output: The sum of all price values in the document.
floor()
Returns the largest integer less than or equal to a given number.
- <xsl:value-of select="floor(12.75)"/>
Output: 12
ceiling()
Returns the smallest integer greater than or equal to a given number.
- <xsl:value-of select="ceiling(12.75)"/>
Output: 13
round()
Rounds a number to the nearest integer.
- <xsl:value-of select="round(12.5)"/>
Output: 13
abs()
Returns the absolute value of a number.
- <xsl:value-of select="abs(-12.75)"/>
Output: 12.75
math:max()
Returns the maximum value from a set of numbers.
- <xsl:value-of select="math:max(3, 5, 7)"/>
Output: 7
math:min()
Returns the minimum value from a set of numbers.
- <xsl:value-of select="math:min(3, 5, 7)"/>
Output: 3
math:highest()
Returns the node with the highest value from a node set.
- <xsl:value-of select="math:highest(/price)"/>
Output: <price item="Computer">1000.00</price>
math:lowest()
Returns the lowest value from a node set.
- <xsl:value-of select="math:lowest(/price)"/>
Output: <price item="Gum">1.00</price>
math:random()
Generates a random number between 0 and 1.
- <xsl:value-of select="math:random()"/>
Node Set Functions
These functions are used to work with node sets, such as selecting XML elements.
last()
Returns the position of the last node in a node set.
- <xsl:value-of select="last()"/>
Output: The position of the last node.
position()
Returns the position of the current node within the node set.
- <xsl:value-of select="position()"/>
Output: The position of the current node in the node set.
count()
Returns the number of nodes in a node set.
- <xsl:value-of select="count(//book)"/>
Output: The number of book elements in the document.
id()
Selects nodes with a specific ID.
- <xsl:value-of select="id('book1')"/>
Output: The element with the ID book1.
Date and Time Functions
These functions are used to parse and processing date values.
date:now()
Returns the current date and time in the specified pattern.
<xsl:value-of select="date:now('dd/MM/yy)"/>
Output: Current date and time like 25-12-24.
Formats a date according to a specified pattern.
<xsl:value-of select="date:formatDate(date:now(), 'yyyy-MM-dd')"/>
Output: A formatted date like 2024-12-16.
date:ticks()
Returns the number of ticks (milliseconds) since January 1, 1970.
<xsl:value-of select="date:ticks()"/>
Output: Current timestamp in milliseconds.
date:add()
Adds a specified number of units (e.g., days, months, etc.) to a date.
<xsl:value-of select="date:add(date:now(), 'P1D')"/>
Output: Current date plus one day.