Date and time

The stylesheets have a feature to generate date and time strings. These can be used to insert the processing date for display or for meta data. These features make use of the EXSLT date-time() function. That function is supported by the Saxon, Xalan, and xsltproc processors, but not MSXSL.

There is no DocBook element that represents the current date, so the stylesheets use a processing instruction to insert a timestamp. The following is an example:

<para>This document was generated 
<?dbtimestamp format="Y-m-d H:M:S"?>.</para>

When processed, this input will result in the following output in either HTML or print:

This document was generated 2007-07-23 12:13:00.

The dbtimestamp processing instruction name triggers the date functions, and the format string is used to select and format the components of date and time. The component letters are as follows:

Date-time format letterExampleDescription
aThuDay abbreviation
AThursdayDay name
bJulMonth abbreviation
c2007-07-10-07:00 12:20:33-07:00Complete ISO date and time, including offset from UTC.
BJulyMonth name
d10Day in month
H11Hour in day
j191Day in year
m07Month in year
M20Minute in hour
S14Second in minute
U28Week in year
w5Day in week (Sunday = 1)
x2007-07-10-07:00ISO date
X12:20:33-07:00ISO time
Y2007Year.

Any other characters in the format string are passed through, allowing you to add punctuation as needed. If no format string is supplied in the processing instruction, then the stylesheet uses the gentext template named format in the context named datetime for the current language, as in the following example for English. See the section “Generated text” for more on gentext templates.

  <l:context name="datetime">
      <l:template name="format" text="m/d/Y"/>
   </l:context>

The dbtimestamp processing instruction supports an option to omit the leading zero for single digit dates and times. That is, if the date value is 5, the stylesheet will output 05 by default. You can turn off the zero padding by setting a pseudo-attribute padding="0" in the processing instruction:

<?dbtimestamp format="Y-m-d"  padding="0" ?>

The change in zero padding applies to hour, minute, and date values used in the processing instruction. If you want it to apply only to date and not minute (you get the odd looking 3:5 for time instead of 3:05), then create two separate dbtimestamp processing instructions for the date and time, and set the padding="0" value only for the date.

You can also use the date functions more directly in a customization layer. See the section “Adding a date timestamp” for an example.