format-date


format-date

The format-date() function is used to output a date in human-readable format. It may also be used to obtain information derived from the date, for example the day of the week on which a particular date falls .

Changes in 2.0

This function is new in XSLT 2.0.

Signature

Argument

Data type

Meaning

date

xs:date?

The date to be formatted.

picture

xs:string

A picture string identifying the components to be output and the format in which they are output.

language (optional)

xs:string?

A string following the same rules as the xml:lang attribute in XML, to indicate the language to be used for formatting the date. For example, «en » indicates English, «de » German, and «es » Spanish.

calendar (optional)

xs:string?

A string giving a code for the calendar to be used for formatting the date.

country (optional)

xs:string?

A code identifying the country associated with the date, for example the country in which the dated event took place.

Result

xs:string?

The formatted date.

The last three arguments are optional, but they must either all be supplied, or all be omitted. That is, the function must be called either with two arguments or with five. Calling it with two arguments is equivalent to supplying an empty sequence «() » for each of the last three arguments; an empty sequence for any of these arguments invokes the default value.

Effect

If the date argument is an empty sequence, then the result is an empty sequence.

The picture string may contain a number of component specifiers, identifying the components to be output. These are described in detail under format-dateTime() , in the following section. If the picture argument includes component specifiers that are not appropriate to a date value (for example, the hours, minutes, and seconds components) then the processor may either report a runtime error, or simply ignore those components.

Apart from this, the effect of the function is the same as that of casting the supplied date value to an xs:dateTime (which gives the xs:dateTime representing 00:00:00 on that date), and calling format-dateTime() with the same value of the $picture argument, and the same value of the $format argument if it is present.

Usage and Examples

The main use of this function is in producing a date formatted for human readers. For example:

  format-date(xs:date('1999-11-16'), '[D] [MNn] [Y]')  

typically produces the output:

  16 November 1999  

This is assuming that the default calendar is the Gregorian calendar, and that the default language is English.

The function can also be used to reformat dates into non-ISO formats where these are required by the target document design. For example, in the United States it is not uncommon to find XML documents in which dates are encoded as MMDDYY, rather than using the XML Schema (and ISO 8601) format YYYY-MM-DD. This output can be produced using a call such as follows .

  format-date(xs:date('1999-11-16'), '[M01][D01][Y01]')  

Full details of the picture string and of the three arguments language , calendar , and country are provided under format-dateTime() in the following section.

See Also

format-dateTime() in the following section.




XSLT 2.0 Programmer's Reference
NetBeansв„ў IDE Field Guide: Developing Desktop, Web, Enterprise, and Mobile Applications (2nd Edition)
ISBN: 764569090
EAN: 2147483647
Year: 2003
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net