source: clfs-embedded/BOOK/stylesheets/lfs-xsl/docbook-xsl-snapshot/common/pi.xsl @ 9882b55

Last change on this file since 9882b55 was 9882b55, checked in by Manuel Canales Esparcia <manuel@…>, 15 years ago

Added the new lfs-xsl stylesheets.

  • Property mode set to 100644
File size: 8.2 KB
Line 
1<?xml version='1.0'?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
4                xmlns:date="http://exslt.org/dates-and-times"
5                xmlns:exsl="http://exslt.org/common"
6                exclude-result-prefixes="doc date exsl"
7                extension-element-prefixes="date exsl"
8                version='1.0'>
9
10<!-- ********************************************************************
11     $Id$
12     ********************************************************************
13
14     This file is part of the XSL DocBook Stylesheet distribution.
15     See ../README or http://docbook.sf.net/release/xsl/current/ for
16     copyright and other information.
17
18     This file contains general templates for processing processing
19     instructions common to both the HTML and FO versions of the
20     DocBook stylesheets.
21     ******************************************************************** -->
22
23<!-- Process PIs also on title pages -->
24<xsl:template match="processing-instruction()" mode="titlepage.mode">
25  <xsl:apply-templates select="."/>
26</xsl:template>
27
28<xsl:template match="processing-instruction('dbtimestamp')">
29  <xsl:variable name="format">
30    <xsl:variable name="pi-format">
31      <xsl:call-template name="pi-attribute">
32        <xsl:with-param name="pis" select="."/>
33        <xsl:with-param name="attribute">format</xsl:with-param>
34      </xsl:call-template>
35    </xsl:variable>
36    <xsl:choose>
37      <xsl:when test="$pi-format != ''">
38        <xsl:value-of select="$pi-format"/>
39      </xsl:when>
40      <xsl:otherwise>
41        <xsl:call-template name="gentext.template">
42          <xsl:with-param name="context" select="'datetime'"/>
43          <xsl:with-param name="name" select="'format'"/>
44        </xsl:call-template>
45      </xsl:otherwise>
46    </xsl:choose>
47  </xsl:variable> 
48
49  <xsl:variable name="padding">
50    <xsl:variable name="pi-padding">
51      <xsl:call-template name="pi-attribute">
52        <xsl:with-param name="pis" select="."/>
53        <xsl:with-param name="attribute">padding</xsl:with-param>
54      </xsl:call-template>
55    </xsl:variable>
56    <xsl:choose>
57      <xsl:when test="$pi-padding != ''">
58        <xsl:value-of select="$pi-padding"/>
59      </xsl:when>
60      <xsl:otherwise>1</xsl:otherwise>
61    </xsl:choose>
62  </xsl:variable>
63
64  <xsl:variable name="date">
65    <xsl:choose>
66      <xsl:when test="function-available('date:date-time')">
67        <xsl:value-of select="date:date-time()"/>
68      </xsl:when>
69      <xsl:when test="function-available('date:dateTime')">
70        <!-- Xalan quirk -->
71        <xsl:value-of select="date:dateTime()"/>
72      </xsl:when>
73    </xsl:choose>
74  </xsl:variable>
75
76  <xsl:choose>
77    <xsl:when test="function-available('date:date-time') or
78                    function-available('date:dateTime')">
79      <xsl:call-template name="datetime.format">
80        <xsl:with-param name="date" select="$date"/>
81        <xsl:with-param name="format" select="$format"/>
82        <xsl:with-param name="padding" select="$padding"/>
83      </xsl:call-template>
84    </xsl:when>
85    <xsl:otherwise>
86      <xsl:message>
87        Timestamp processing requires XSLT processor with EXSLT date support.
88      </xsl:message>
89    </xsl:otherwise>
90  </xsl:choose>
91
92</xsl:template>
93
94<xsl:template name="datetime.format">
95  <xsl:param name="date"/>
96  <xsl:param name="format"/>
97  <xsl:param name="padding" select="1"/>
98 
99  <xsl:if test="$format != ''">
100    <!-- replace any whitespace in the format string with a non-breaking space -->
101    <xsl:variable name="format-nbsp"
102                  select="translate($format,
103                          '&#x20;&#x9;&#xd;&#xa;',
104                          '&#xa0;&#xa0;&#xa0;&#xa0;')"/>
105    <xsl:variable name="tokenized-format-string">
106      <xsl:call-template name="str.tokenize.keep.delimiters">
107        <xsl:with-param name="string" select="$format-nbsp"/>
108        <xsl:with-param name="delimiters" select="'&#xa0;,./-()[]:'"/>
109      </xsl:call-template>
110    </xsl:variable>
111
112  <xsl:choose>
113    <!-- include extra test for Xalan quirk -->
114    <xsl:when test="function-available('exsl:node-set') or
115                    contains(system-property('xsl:vendor'),'Apache Software Foundation')">
116      <!-- We must preserve context node in order to get valid language -->
117      <xsl:variable name="context" select="."/>
118      <xsl:for-each select="exsl:node-set($tokenized-format-string)/node()">
119        <xsl:variable name="token">
120          <xsl:value-of select="."/>
121        </xsl:variable>
122        <!-- Restore context node -->
123        <xsl:for-each select="$context">
124          <xsl:choose>
125            <xsl:when test="$token = 'a'">
126              <xsl:call-template name="gentext.template">
127                <xsl:with-param name="context" select="'datetime-abbrev'"/>
128                <xsl:with-param name="name" select="date:day-abbreviation($date)"/>
129              </xsl:call-template>
130            </xsl:when>
131            <xsl:when test="$token = 'A'">
132              <xsl:call-template name="gentext.template">
133                <xsl:with-param name="context" select="'datetime-full'"/>
134                <xsl:with-param name="name" select="date:day-name($date)"/>
135              </xsl:call-template>
136            </xsl:when>
137            <xsl:when test="$token = 'b'">
138              <xsl:call-template name="gentext.template">
139                <xsl:with-param name="context" select="'datetime-abbrev'"/>
140                <xsl:with-param name="name" select="date:month-abbreviation($date)"/>
141              </xsl:call-template>
142            </xsl:when>
143            <xsl:when test="$token = 'c'">
144              <xsl:value-of select="date:date($date)"/>
145              <xsl:text> </xsl:text>
146              <xsl:value-of select="date:time($date)"/>
147            </xsl:when>
148            <xsl:when test="$token = 'B'">
149              <xsl:call-template name="gentext.template">
150                <xsl:with-param name="context" select="'datetime-full'"/>
151                <xsl:with-param name="name" select="date:month-name($date)"/>
152              </xsl:call-template>
153            </xsl:when>
154            <xsl:when test="$token = 'd'">
155              <xsl:if test="$padding = 1 and
156              string-length(date:day-in-month($date)) = 1">0</xsl:if>
157              <xsl:value-of select="date:day-in-month($date)"/>
158            </xsl:when>
159            <xsl:when test="$token = 'H'">
160              <xsl:if test="$padding = 1 and string-length(date:hour-in-day($date)) = 1">0</xsl:if>
161              <xsl:value-of select="date:hour-in-day($date)"/>
162            </xsl:when>
163            <xsl:when test="$token = 'j'">
164              <xsl:value-of select="date:day-in-year($date)"/>
165            </xsl:when>
166            <xsl:when test="$token = 'm'">
167              <xsl:if test="$padding = 1 and string-length(date:month-in-year($date)) = 1">0</xsl:if>
168              <xsl:value-of select="date:month-in-year($date)"/>
169            </xsl:when>
170            <xsl:when test="$token = 'M'">
171              <xsl:if test="string-length(date:minute-in-hour($date)) = 1">0</xsl:if>
172              <xsl:value-of select="date:minute-in-hour($date)"/>
173            </xsl:when>
174            <xsl:when test="$token = 'S'">
175              <xsl:if test="string-length(date:second-in-minute($date)) = 1">0</xsl:if>
176              <xsl:value-of select="date:second-in-minute($date)"/>
177            </xsl:when>
178            <xsl:when test="$token = 'U'">
179              <xsl:value-of select="date:week-in-year($date)"/>
180            </xsl:when>
181            <xsl:when test="$token = 'w'">
182              <xsl:value-of select="date:day-in-week($date)"/>
183            </xsl:when>
184            <xsl:when test="$token = 'x'">
185              <xsl:value-of select="date:date($date)"/>
186            </xsl:when>
187            <xsl:when test="$token = 'X'">
188              <xsl:value-of select="date:time($date)"/>
189            </xsl:when>
190            <xsl:when test="$token = 'Y'">
191              <xsl:value-of select="date:year($date)"/>
192            </xsl:when>
193            <xsl:otherwise>
194              <xsl:value-of select="$token"/>
195            </xsl:otherwise>
196          </xsl:choose>
197        </xsl:for-each>
198      </xsl:for-each>
199    </xsl:when>
200    <xsl:otherwise>
201      <xsl:message>
202        Timestamp processing requires an XSLT processor with support
203        for the EXSLT node-set() function.
204      </xsl:message>
205    </xsl:otherwise>
206  </xsl:choose>
207  </xsl:if>
208
209</xsl:template>
210
211</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.