XPath Functions
XPath provides many functions that you may find useful in
predicates or raw expressions. All of these are discussed in Chapter 23. For example, the position() function returns the position of
the current node in the context node list as a number. This XSLT
template rule uses the position( )
function to calculate the number of the person being processed, relative to other
nodes in the context node list:
<xsl:template match="person"> Person <xsl:value-of select="position( )"/>, <xsl:value-of select="name"/> </xsl:template>
Each XPath function returns one of these four types:
Boolean
Number
Node-set
String
There are no void functions in XPath; it is not nearly as strongly typed as languages like Java or even C. You can often use any of these types as a function argument regardless of which type the function expects, and the processor will convert it as best it can. For example, if you insert a Boolean where a string is expected, then the processor will substitute one of the two strings “true” or “false” for the Boolean. The one exception is functions that expect to receive node-sets as arguments. XPath cannot convert strings, Booleans, or numbers to node-sets.
Functions are identified by the parentheses at the end of the
function name. Sometimes functions take arguments between the
parentheses. For instance, the round() function takes a single number as an
argument. It returns the number rounded to the nearest integer. For
example, <xsl:value-of
select="round(3.14)"/> inserts ...