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 letter | Example | Description |
---|---|---|
a | Thu | Day abbreviation |
A | Thursday | Day name |
b | Jul | Month abbreviation |
c | 2007-07-10-07:00 12:20:33-07:00 | Complete ISO date and time, including offset from UTC. |
B | July | Month name |
d | 10 | Day in month |
H | 11 | Hour in day |
j | 191 | Day in year |
m | 07 | Month in year |
M | 20 | Minute in hour |
S | 14 | Second in minute |
U | 28 | Week in year |
w | 5 | Day in week (Sunday = 1) |
x | 2007-07-10-07:00 | ISO date |
X | 12:20:33-07:00 | ISO time |
Y | 2007 | Year. |
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.
DocBook XSL: The Complete Guide - 4th Edition | PDF version available | Copyright © 2002-2007 Sagehill Enterprises |