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:

  1. Create a customization file
    Create a customization file as shown in Creating a customization file.

  2. 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>

  1. 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> 

  1. 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.

  

back to top