XML technologies / DocBook / The DocBook XSL stylesheets / Inserting the current time and date

(Excerpt from "DocBook-XML: Media-neutral and platform-independent publishing" by Thomas Schraitle)

With the processing instruction <?dbtimestamp?> you can insert the current time and date in your DocBook document. This has been supported by the DocBook XSLT stylesheets (see the file common/pi.xsl) since version 1.61.1. The simplest way to insert the current date is with the following code:

<para>Aktuelles Datum: <?dbtimestamp?>.</para>

The processing instruction <?dbtimestamp?> can do more, however: using the pseudo-attribute format you can use letters to control the output (similar to the printf function). The following notation therefore outputs the current month:

<para>Aktueller Monat: <?dbtimestampformat="B"?></para>

Note that you need an XSLT processor that supports EXSLT’s date functions. This should apply to the most common processors, such as xsltproc, Saxon and Xalan.

The following letters are available as of stylesheet version 1.61.1:  

Table: Time and date placeholders

Characters

Meaning

A

the full, localized weekday name

a

the abbreviated, localized weekday name, such as Mon for Monday, Die for Tuesday, etc.

B

the full, localized month name

b

the abbreviated, localized month name, such as Jan for January, Feb for February, etc.

c

returns the date and time in the same format as x and X

d

the day ( day) as a number from 01 to 31

H

the hour ( hour) as a number from 00 to 23

M

the minutes as a number from 00 to 59

m

the current month as a number from 01 to 12

j

the number of days elapsed in the year

S

the seconds as a number from 00 to 59

U

returns the week number of the year, numbered according to ISO 8601. The first week contains the first Tuesday of the year. All subsequent weeks begin on a Monday.

w

a number from 1 to 7 identifying the weekday; numbering starts with 1 for Sunday, 2 for Monday, etc.

X

time in the following format: Hours: Minutes: Seconds[+|-] Time offset

x

date in the following format: Year- Month- Day[+|-] Time offset

Y

year as a four-digit number

Using the pseudo-attribute padding you can display leading zeros (1, the default) or suppress them (0). This applies to the letters d, H and m. Thus, a processing instruction such as

<?dbtimestamp format="A, d. B Y"?> 

produces a date such as:

Donnerstag, 09. Juni 2003

whereas adding padding="0" produces the following output:

Donnerstag, 9. Juni 2003

  

back to top