Chapter 3. Dates and Times

Does anyone really know what time it is? Does anyone really care?

Chicago

Introduction

Native XSLT 1.0 does not know what time it is and does not seem to care. However, dates and times are a necessary aspect of everyday life. The need to manipulate them arises frequently in computing, especially in web development. Therefore, it is surprising and unfortunate that standard XSLT does not have any built-in date and time support.

The examples in this section can help compensate for XSLT’s lack of support for dates and times. Unfortunately, one of the most crucial date and time capabilities cannot be implemented in XSLT—that is, getting the current date and time. For that, you need to call out to another language whose library supports interacting with the hardware’s real-time clock. Both Java and JavaScript have this capability. If your application just needs to format dates and times that already exist in a document, then the routines here should cover most needs.

Data and time manipulation and conversion can be tricky, but it is almost purely an exercise in intricate integer arithmetic involving what are essentially base conversions in a mixed radix system. Working with non-Gregorian calendars and determining holidays also requires quite a bit of historical, religious, and cultural knowledge. Readers with no application for date and time routines may wish to skip this chapter because little by way of XSLT technique is unique to these algorithms. Those who ...

Get XSLT Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.