Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
If the picture string is invalid, then the implementation is required to report an error.
Usage
Note that this facility for formatting numbers is completely separate from the facilities available through the
format-number()
function formats a single number, which need not be an integer.
Examples
The following example shows the result of
format-number()
using the default decimal format. Examples with non-default decimal formats are shown under the
Number | Picture String | Result |
1234.5 | #,##0.00 | 1,234.50 |
123.456 | #,##0.00 | 123.46 |
1000000 | #,##0.00 | 1,000,000.00 |
-59 | #,##0.00 | -59.00 |
1 div 0.0e0 | #,##0.00 | Infinity |
1234 | ###0.0### | 1234.0 |
1234.5 | ###0.0### | 1234.5 |
.00025 | ###0.0### | 0.0002 |
.00035 | ###0.0### | 0.0004 |
0.25 | #00% | 25% |
0.736 | #00% | 74% |
1 | #00% | 100% |
-42 | #00% | -4200% |
-3.12 | #.00;(#.00) | (3.12) |
-3.12 | #.00;#.00CR | 3.12CR |
See Also
format-time
See
format-date()
on page 781
function-available
This function is available in XSLT only
.
You can call
function-available()
to test whether a particular function is available for use. It can be used to test the availability both of standard system functions and of user-written functions, including both XSLT stylesheet functions and extension functions.
For example, the expression
function-available(‘concat’)
returns
true
.
Changes in 2.0
An optional second argument has been added, giving the arity of the required function.
In XSLT 2.0, except when running in backward-compatibility mode, it is a static error if an XPath expression contains a call on a function that is not available. Therefore, the way in which
function-available()
is used needs to change: instead of calling it using a normal runtime conditional instruction
(
[xsl:]use-when
attribute.
Signature
Argument | Type | Meaning |
name | xs:string | The name of the function being tested. The string must take the form of a lexical QName . |
arity (optional) | xs:integer | The arity (number of arguments) of the function being tested. |
Result | xs:boolean | true if the named function is available to be called , false otherwise . |
Effect
The first argument must take the form of a lexical
QName
: that is, an XML name, with an optional namespace prefix that corresponds to a namespace declaration that is in scope at the point in the stylesheet where the
function-available()
function is called.
If there is no prefix, or if the namespace URI is the standard function namespace
http://www.w3.org/2005/xpath-functions
, the call tests whether there is a system function with the specified name. The system functions are those defined in the XPath and XSLT Recommendations; vendors are not allowed to supply additional functions in this namespace, nor are they allowed to omit any. So an XSLT processor that conforms to XSLT version 2.0 will return
true
if the name is one of the function names in this chapter (for example
current
,
position
, or
regex-group
). This means you can test whether a new XPath 2.0 or XSLT 2.0 function is supported in your XSLT processor by writing, for example:
use-when=“function-available(‘matches’)”
use-when=“function-available(‘regex-group’)”
If the
QName
includes a non-null namespace (other than the standard function namespace), the XSLT processor returns
true
if there is a stylesheet function, constructor function, or extension function available with the given name. In general, if
function-available()
returns
false
, then you are safe in assuming that a call on the function would fail, and if it returns
true
, then there will be some way of calling the function successfully.
If the second argument to the function is supplied, then
function-available()
returns
true
only if there is a function available with the specified name and the specified number of arguments. When the second argument is omitted, the result is true if there is some function with the required name, regardless of the number of arguments.