XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (92 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
3.95Mb size Format: txt, pdf, ePub
ads

xs:date

The
xs:date
type represents a date. The lexical representation of the date (that is, the way it appears in a textual XML document) is always the representation defined in the ISO 8601 standard, that is
YYYY-MM-DD
(for example,
1999-11-16
for November 16, 1999). This format is chosen because it is unambiguous; the theory is that XML documents should represent information in a neutral form that is independent of how different users might want to see the information formatted.

For formatting dates and times in a user-friendly way, XSLT provides the
format-date()
function, which is described in Chapter 13. This isn't available in standalone XPath expressions (or in XQuery).

A rather quirky feature of the
xs:date
type is that as well as holding the date itself, it can also hold a timezone. This is something that ISO 8601 itself doesn't allow. The idea is that a date actually represents a period of 24 hours starting at midnight in a particular timezone, and ending at the following midnight in the same timezone. The date November 16, 1999 represents a different period of 24 hours in New York from the period it represents in London, Tokyo, or Los Angeles, so the schema designers came up with the idea of adding a timezone to the date to indicate exactly when the date begins and ends. In the lexical representation, the timezone is added after the date part, for example
1999-11-16-05:00
represents a date in the timezone that is five hours behind UTC (the timezone used in the Eastern United States during the winter months). The timezone is optional; it is also possible to have a date value with no timezone, in which case the precise beginning and end of the 24-hour period represented by the value are considered to be unknown.

XML Schema doesn't define how dates are represented internally in the system, but it does define a
value space
for every type. If two different lexical values translate into the same value in the value space, then they are completely equivalent (to the extent that when you copy an element or attribute, the original lexical representation won't necessarily be retained). For dates (as distinct from times) the XML Schema and XPath specifications agree that the timezone is part of the value space: that is,
1999-11-16-05:00
represents a different
xs:date
value from
1999-11-16+01:00
. However,
1999-11-16+13:00
(used in Tonga) is equivalent to
1999-11-15-11:00
(used in nearby Samoa), because both dates start at the same instant.

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
3.95Mb size Format: txt, pdf, ePub
ads

Other books

The Notebook by Nicholas Sparks
Love Lessons by Alice K. Cross
Grimm Tales by John Kenyon
Danger on Vampire Trail by Franklin W. Dixon
Petra K and the Blackhearts by M. Henderson Ellis
Asylum by Jason Sizemore
As It Is On Telly by Marshall, Jill
One Good Knight by Mercedes Lackey