Rocco Rutte:
[apps/madmutt.git] / doc / xslt / common / pi.xsl
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://nwalsh.com/docbook/xsl/ for copyright
16      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     <xsl:when test="function-available('exsl:node-set')">
114       <!-- We must preserve context node in order to get valid language -->
115       <xsl:variable name="context" select="."/>
116       <xsl:for-each select="exsl:node-set($tokenized-format-string)/node()">
117         <xsl:variable name="token">
118           <xsl:value-of select="."/>
119         </xsl:variable>
120         <!-- Restore context node -->
121         <xsl:for-each select="$context">
122           <xsl:choose>
123             <xsl:when test="$token = 'a'">
124               <xsl:call-template name="gentext.template">
125                 <xsl:with-param name="context" select="'datetime-abbrev'"/>
126                 <xsl:with-param name="name" select="date:day-abbreviation($date)"/>
127               </xsl:call-template>
128             </xsl:when>
129             <xsl:when test="$token = 'A'">
130               <xsl:call-template name="gentext.template">
131                 <xsl:with-param name="context" select="'datetime-full'"/>
132                 <xsl:with-param name="name" select="date:day-name($date)"/>
133               </xsl:call-template>
134             </xsl:when>
135             <xsl:when test="$token = 'b'">
136               <xsl:call-template name="gentext.template">
137                 <xsl:with-param name="context" select="'datetime-abbrev'"/>
138                 <xsl:with-param name="name" select="date:month-abbreviation($date)"/>
139               </xsl:call-template>
140             </xsl:when>
141             <xsl:when test="$token = 'c'">
142               <xsl:value-of select="date:date($date)"/>
143               <xsl:text> </xsl:text>
144               <xsl:value-of select="date:time($date)"/>
145             </xsl:when>
146             <xsl:when test="$token = 'B'">
147               <xsl:call-template name="gentext.template">
148                 <xsl:with-param name="context" select="'datetime-full'"/>
149                 <xsl:with-param name="name" select="date:month-name($date)"/>
150               </xsl:call-template>
151             </xsl:when>
152             <xsl:when test="$token = 'd'">
153               <xsl:if test="$padding = 1 and
154               string-length(date:day-in-month($date)) = 1">0</xsl:if>
155               <xsl:value-of select="date:day-in-month($date)"/>
156             </xsl:when>
157             <xsl:when test="$token = 'H'">
158               <xsl:if test="$padding = 1 and string-length(date:hour-in-day($date)) = 1">0</xsl:if>
159               <xsl:value-of select="date:hour-in-day($date)"/>
160             </xsl:when>
161             <xsl:when test="$token = 'j'">
162               <xsl:value-of select="date:day-in-year($date)"/>
163             </xsl:when>
164             <xsl:when test="$token = 'm'">
165               <xsl:if test="$padding = 1 and string-length(date:month-in-year($date)) = 1">0</xsl:if>
166               <xsl:value-of select="date:month-in-year($date)"/>
167             </xsl:when>
168             <xsl:when test="$token = 'M'">
169               <xsl:if test="string-length(date:minute-in-hour($date)) = 1">0</xsl:if>
170               <xsl:value-of select="date:minute-in-hour($date)"/>
171             </xsl:when>
172             <xsl:when test="$token = 'S'">
173               <xsl:if test="string-length(date:second-in-minute($date)) = 1">0</xsl:if>
174               <xsl:value-of select="date:second-in-minute($date)"/>
175             </xsl:when>
176             <xsl:when test="$token = 'U'">
177               <xsl:value-of select="date:week-in-year($date)"/>
178             </xsl:when>
179             <xsl:when test="$token = 'w'">
180               <xsl:value-of select="date:day-in-week($date)"/>
181             </xsl:when>
182             <xsl:when test="$token = 'x'">
183               <xsl:value-of select="date:date($date)"/>
184             </xsl:when>
185             <xsl:when test="$token = 'X'">
186               <xsl:value-of select="date:time($date)"/>
187             </xsl:when>
188             <xsl:when test="$token = 'Y'">
189               <xsl:value-of select="date:year($date)"/>
190             </xsl:when>
191             <xsl:otherwise>
192               <xsl:value-of select="$token"/>
193             </xsl:otherwise>
194           </xsl:choose>
195         </xsl:for-each>
196       </xsl:for-each>
197     </xsl:when>
198     <xsl:otherwise>
199       <xsl:message>
200         Timestamp processing requires an XSLT processor with support
201         for the EXSLT node-set() function.
202       </xsl:message>
203     </xsl:otherwise>
204   </xsl:choose>
205   </xsl:if>
206
207 </xsl:template>
208
209 </xsl:stylesheet>