XML technologies / DocBook / The DocBook XSL stylesheets / Customizing a title page directly / Displaying the current date
Displaying the current date
(Excerpt from "DocBook-XML: Media-neutral and platform-independent publishing" by Thomas Schraitle)
Publication dates can be inserted automatically on title pages. This requires an extension function from EXSLT. Proceed as follows:
Create a customization file
Create a customization file as shown in Creating a customization file.Adding a parameter
Add a parameter after the xsl:import instruction. This parameter describes the date format:
<xsl:param name="date.format">d-B-Y</xsl:param>Making the changes
Add these changes to your customization file:
<xsl:template name="article.titlepage.verso">
<xsl:choose>
<xsl:when test="function-available('date:date-time') or function-available('date:dateTime')">
<div class="titlepage-verso">
<p>
<xsl:call-template name="gentext">
<xsl:with-param name="key" select="'Published'"/>
</xsl:call-template>
<xsl:text>: </xsl:text>
<xsl:call-template name="datetime.format">
<xsl:with-param name="date">
<xsl:choose>
<xsl:when test="function-available('date:date-time')">
<xsl:value-of select="date:date-time()"/>
</xsl:when>
<xsl:when test="function-available('date:dateTime')">
<!-- Xalan Eigenart: -->
<xsl:value-of select="date:dateTime()"/>
</xsl:when>
</xsl:choose>
</xsl:with-param>
<xsl:with-param name="format" select="$date.format"/>
</xsl:call-template>
</p>
</div>
</xsl:when>
<xsl:otherwise>
<xsl:message>Sie benötigen einen XSLT-Prozessor mit EXSLT und date-Unterstützung.</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:template> Transforming
Transform your document using the customization file.
These steps also work for XSL-FO. Simply replace the div element from (X)HTML with fo:block from XSL-FO.
The customization file outputs the publication date in the template article.titlepage.verso. It therefore appears after the titlepage elements. Inside the template, function-available checks whether the EXSLT function date:date-time or date:dateTime is available. This requires an XSLT processor supporting these functions. If successful, a div element outputs the localized string for Published; in German this is Veröffentlicht. Next, the template datetime.format formats the date according to a format specification. The format is stored in the parameter date.format. The exact syntax is described in Inserting the current date and time.
Copyright © 2009 Millin Verlag
You may print the online version for your private use.
Otherwise, this chapter from "DocBook-XML: Medienneutrales und plattformunabhängiges Publizieren" is subject to the same provisions as the printed edition: the work, including all its parts, is protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Millin Verlag, Siebengebirgsring 36, 53797 Lohmar, info(at)millin.de
back to top