]> git.lyx.org Git - lyx.git/blob - lib/docbook/common/pi.xsl
* ca/Intro.lyx from Daniel
[lyx.git] / lib / docbook / common / pi.xsl
1 <?xml version='1.0'?>
2 <xsl:stylesheet
3   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4   xmlns:d="http://docbook.org/ns/docbook"
5   xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
6   xmlns:date="http://exslt.org/dates-and-times"
7   xmlns:exsl="http://exslt.org/common"
8   xmlns:xlink="http://www.w3.org/1999/xlink"
9   exclude-result-prefixes="doc date exsl d"
10   extension-element-prefixes="date exsl"
11   version='1.0'>
12
13 <!-- ********************************************************************
14
15      This file is part of the XSL DocBook Stylesheet distribution.
16      See ../README or http://cdn.docbook.org/release/xsl/current/ for
17      copyright and other information.
18
19      ******************************************************************** -->
20
21 <doc:reference xmlns=""><info><title>Common Processing Instruction Reference</title>
22     <releaseinfo role="meta">
23     </releaseinfo>
24   </info>
25   <partintro id="partintro">
26     <title>Introduction</title>
27     <para>This is generated reference documentation for all
28       user-specifiable processing instructions (PIs) in the
29       “common” part of the DocBook XSL stylesheets.
30       <note>
31         <para>You add these PIs at particular points in a document to
32           cause specific “exceptions” to formatting/output behavior. To
33           make global changes in formatting/output behavior across an
34           entire document, it’s better to do it by setting an
35           appropriate stylesheet parameter (if there is one).</para>
36       </note>
37     </para>
38   </partintro>
39 </doc:reference>
40
41 <!-- ==================================================================== -->
42 <doc:pi name="dbchoice_choice" xmlns="">
43   <refpurpose>Generates a localized choice separator</refpurpose>
44   <refdescription id="select.choice.separator-desc">
45     <para>Use the <tag class="xmlpi">dbchoice choice</tag> PI to
46       generate an appropriate localized “choice” separator (for
47       example, <literal>and</literal> or <literal>or</literal>)
48       before the final item in an inline <tag>simplelist</tag></para>
49     <warning>
50       <para>This PI is a less-than-ideal hack; support for it may
51         disappear in the future (particularly if and when a more
52         appropriate means for marking up "choice" lists becomes
53         available in DocBook).</para>
54     </warning>
55   </refdescription>
56   <refsynopsisdiv>
57     <synopsis><tag class="xmlpi">dbchoice choice="and"|"or"|<replaceable>string</replaceable>"</tag></synopsis>
58   </refsynopsisdiv>
59   <refparameter>
60     <variablelist>
61       <varlistentry><term>choice="and"</term>
62         <listitem>
63           <para>generates a localized <literal>and</literal> separator</para>
64         </listitem>
65       </varlistentry>
66       <varlistentry><term>choice="or"</term>
67         <listitem>
68           <para>generates a localized <literal>or</literal> separator</para>
69         </listitem>
70       </varlistentry>
71       <varlistentry><term>choice="<replaceable>string</replaceable>"</term>
72         <listitem>
73           <para>generates a literal <replaceable>string</replaceable> separator</para>
74         </listitem>
75       </varlistentry>
76     </variablelist>
77   </refparameter>
78 </doc:pi>
79 <xsl:template name="pi.dbchoice_choice">
80   <xsl:param name="node" select="."/>
81   <xsl:call-template name="pi-attribute">
82     <xsl:with-param name="pis" select="$node/processing-instruction('dbchoice')"/>
83     <xsl:with-param name="attribute">choice</xsl:with-param>
84   </xsl:call-template>
85 </xsl:template>
86
87 <doc:pi name="dbtimestamp" xmlns="">
88   <refpurpose>Inserts a date timestamp</refpurpose>
89   <refdescription>
90     <para>Use the <tag class="xmlpi">dbtimestamp</tag> PI at any point in a
91       source document to cause a date timestamp (a formatted
92       string representing the current date and time) to be
93       inserted in output of the document.</para>
94   </refdescription>
95   <refsynopsisdiv>
96     <synopsis><tag class="xmlpi">dbtimestamp format="<replaceable>formatstring</replaceable>" [padding="0"|"1"]</tag></synopsis>
97   </refsynopsisdiv>
98   <refparameter>
99     <variablelist>
100       <varlistentry><term>format="<replaceable>formatstring</replaceable>"</term>
101         <listitem>
102           <para>Specifies format in which the date and time are
103             output</para>
104         <note>
105           <para>For details of the content of the format string,
106             see <link role="tcg" xlink:href="Datetime.html"
107               >Date and time</link>.</para>
108         </note>
109         </listitem>
110       </varlistentry>
111       <varlistentry><term>padding="0"|"1"</term>
112         <listitem>
113           <para>Specifies padding behavior; if non-zero, padding is is added</para>
114         </listitem>
115       </varlistentry>
116     </variablelist>
117   </refparameter>
118 </doc:pi>
119 <xsl:template name="pi.dbtimestamp">
120   <xsl:variable name="format">
121     <xsl:variable name="pi-format">
122       <xsl:call-template name="pi-attribute">
123         <xsl:with-param name="pis" select="."/>
124         <xsl:with-param name="attribute">format</xsl:with-param>
125       </xsl:call-template>
126     </xsl:variable>
127     <xsl:choose>
128       <xsl:when test="$pi-format != ''">
129         <xsl:value-of select="$pi-format"/>
130       </xsl:when>
131       <xsl:otherwise>
132         <xsl:call-template name="gentext.template">
133           <xsl:with-param name="context" select="'datetime'"/>
134           <xsl:with-param name="name" select="'format'"/>
135         </xsl:call-template>
136       </xsl:otherwise>
137     </xsl:choose>
138   </xsl:variable> 
139   <xsl:variable name="padding">
140     <xsl:variable name="pi-padding">
141       <xsl:call-template name="pi-attribute">
142         <xsl:with-param name="pis" select="."/>
143         <xsl:with-param name="attribute">padding</xsl:with-param>
144       </xsl:call-template>
145     </xsl:variable>
146     <xsl:choose>
147       <xsl:when test="$pi-padding != ''">
148         <xsl:value-of select="$pi-padding"/>
149       </xsl:when>
150       <xsl:otherwise>1</xsl:otherwise>
151     </xsl:choose>
152   </xsl:variable>
153   <xsl:variable name="date">
154     <xsl:choose>
155       <xsl:when test="function-available('date:date-time')">
156         <xsl:value-of select="date:date-time()"/>
157       </xsl:when>
158       <xsl:when test="function-available('date:dateTime')">
159         <!-- Xalan quirk -->
160         <xsl:value-of select="date:dateTime()"/>
161       </xsl:when>
162     </xsl:choose>
163   </xsl:variable>
164   <xsl:choose>
165     <xsl:when test="function-available('date:date-time') or
166       function-available('date:dateTime')">
167       <xsl:call-template name="datetime.format">
168         <xsl:with-param name="date" select="$date"/>
169         <xsl:with-param name="format" select="$format"/>
170         <xsl:with-param name="padding" select="$padding"/>
171       </xsl:call-template>
172     </xsl:when>
173     <xsl:otherwise>
174       <xsl:message>
175         Timestamp processing requires XSLT processor with EXSLT date support.
176       </xsl:message>
177     </xsl:otherwise>
178   </xsl:choose>
179 </xsl:template>
180
181 <doc:pi name="dbtex_delims" xmlns="">
182   <refpurpose>Generates delimiters around embedded TeX equations
183     in output</refpurpose>
184   <refdescription>
185     <para>Use the <tag class="xmlpi">dbtex delims</tag> PI as a
186       child of a <tag>textobject</tag> containing embedded TeX
187       markup, to cause that markup to be surrounded by
188       <literal>$</literal> delimiter characters in output.</para>
189       <warning>
190        <para>This feature is useful for print/PDF output only if you
191        use the obsolete and now unsupported PassiveTeX XSL-FO
192        engine.</para>
193       </warning>
194   </refdescription>
195   <refsynopsisdiv>
196     <synopsis><tag class="xmlpi">dbtex delims="no"|"yes"</tag></synopsis>
197   </refsynopsisdiv>
198   <refparameter>
199     <variablelist>
200       <varlistentry><term>dbtex delims="no"|"yes"</term>
201         <listitem>
202           <para>Specifies whether delimiters are output</para>
203         </listitem>
204       </varlistentry>
205     </variablelist>
206   </refparameter>
207
208   <refsee role="params">
209     <para><parameter>tex.math.delims</parameter></para>
210   </refsee>
211  
212 </doc:pi>
213 <xsl:template name="pi.dbtex_delims">
214   <xsl:param name="node" select="."/>
215   <xsl:call-template name="pi-attribute">
216     <xsl:with-param name="pis" select="$node/processing-instruction('dbtex')"/>
217     <xsl:with-param name="attribute" select="'delims'"/>
218   </xsl:call-template>
219 </xsl:template>
220
221 <!-- ==================================================================== -->
222
223 <xsl:template match="processing-instruction()" mode="titlepage.mode">
224   <!-- * Als process PIs on title pages -->
225   <xsl:apply-templates select="."/>
226 </xsl:template>
227
228 <xsl:template match="processing-instruction('dbtimestamp')">
229   <xsl:call-template name="pi.dbtimestamp"/>
230 </xsl:template>
231
232 <xsl:template name="datetime.format">
233   <xsl:param name="date"/>
234   <xsl:param name="format"/>
235   <xsl:param name="padding" select="1"/>
236   <xsl:if test="$format != ''">
237     <!-- replace any whitespace in the format string with a non-breaking space -->
238     <xsl:variable name="format-nbsp"
239       select="translate($format,
240       '&#x20;&#x9;&#xd;&#xa;',
241       '&#xa0;&#xa0;&#xa0;&#xa0;')"/>
242     <xsl:variable name="tokenized-format-string">
243       <xsl:call-template name="str.tokenize.keep.delimiters">
244         <xsl:with-param name="string" select="$format-nbsp"/>
245         <xsl:with-param name="delimiters" select="'&#xa0;,./-()[]:'"/>
246       </xsl:call-template>
247     </xsl:variable>
248     <xsl:choose>
249       <xsl:when test="$exsl.node.set.available != 0">
250         <!-- We must preserve context node in order to get valid language -->
251         <xsl:variable name="context" select="."/>
252         <xsl:for-each select="exsl:node-set($tokenized-format-string)/node()">
253           <xsl:variable name="token">
254             <xsl:value-of select="."/>
255           </xsl:variable>
256           <!-- Restore context node -->
257           <xsl:for-each select="$context">
258             <xsl:choose>
259               <xsl:when test="$token = 'a'">
260                 <xsl:call-template name="gentext.template">
261                   <xsl:with-param name="context" select="'datetime-abbrev'"/>
262                   <xsl:with-param name="name" select="date:day-abbreviation($date)"/>
263                 </xsl:call-template>
264               </xsl:when>
265               <xsl:when test="$token = 'A'">
266                 <xsl:call-template name="gentext.template">
267                   <xsl:with-param name="context" select="'datetime-full'"/>
268                   <xsl:with-param name="name" select="date:day-name($date)"/>
269                 </xsl:call-template>
270               </xsl:when>
271               <xsl:when test="$token = 'b'">
272                 <xsl:call-template name="gentext.template">
273                   <xsl:with-param name="context" select="'datetime-abbrev'"/>
274                   <xsl:with-param name="name" select="date:month-abbreviation($date)"/>
275                 </xsl:call-template>
276               </xsl:when>
277               <xsl:when test="$token = 'c'">
278                 <xsl:value-of select="date:date($date)"/>
279                 <xsl:text> </xsl:text>
280                 <xsl:value-of select="date:time($date)"/>
281               </xsl:when>
282               <xsl:when test="$token = 'B'">
283                 <xsl:call-template name="gentext.template">
284                   <xsl:with-param name="context" select="'datetime-full'"/>
285                   <xsl:with-param name="name" select="date:month-name($date)"/>
286                 </xsl:call-template>
287               </xsl:when>
288               <xsl:when test="$token = 'd'">
289                 <xsl:if test="$padding = 1 and
290                   string-length(date:day-in-month($date)) = 1">0</xsl:if>
291                 <xsl:value-of select="date:day-in-month($date)"/>
292               </xsl:when>
293               <xsl:when test="$token = 'H'">
294                 <xsl:if test="$padding = 1 and string-length(date:hour-in-day($date)) = 1">0</xsl:if>
295                 <xsl:value-of select="date:hour-in-day($date)"/>
296               </xsl:when>
297               <xsl:when test="$token = 'j'">
298                 <xsl:value-of select="date:day-in-year($date)"/>
299               </xsl:when>
300               <xsl:when test="$token = 'm'">
301                 <xsl:if test="$padding = 1 and string-length(date:month-in-year($date)) = 1">0</xsl:if>
302                 <xsl:value-of select="date:month-in-year($date)"/>
303               </xsl:when>
304               <xsl:when test="$token = 'M'">
305                 <xsl:if test="string-length(date:minute-in-hour($date)) = 1">0</xsl:if>
306                 <xsl:value-of select="date:minute-in-hour($date)"/>
307               </xsl:when>
308               <xsl:when test="$token = 'S'">
309                 <xsl:if test="string-length(date:second-in-minute($date)) = 1">0</xsl:if>
310                 <xsl:value-of select="date:second-in-minute($date)"/>
311               </xsl:when>
312               <xsl:when test="$token = 'U'">
313                 <xsl:value-of select="date:week-in-year($date)"/>
314               </xsl:when>
315               <xsl:when test="$token = 'w'">
316                 <xsl:value-of select="date:day-in-week($date)"/>
317               </xsl:when>
318               <xsl:when test="$token = 'x'">
319                 <xsl:value-of select="date:date($date)"/>
320               </xsl:when>
321               <xsl:when test="$token = 'X'">
322                 <xsl:value-of select="date:time($date)"/>
323               </xsl:when>
324               <xsl:when test="$token = 'Y'">
325                 <xsl:value-of select="date:year($date)"/>
326               </xsl:when>
327               <xsl:otherwise>
328                 <xsl:value-of select="$token"/>
329               </xsl:otherwise>
330             </xsl:choose>
331           </xsl:for-each>
332         </xsl:for-each>
333       </xsl:when>
334       <xsl:otherwise>
335         <xsl:message>
336           Timestamp processing requires an XSLT processor with support
337           for the EXSLT node-set() function.
338         </xsl:message>
339       </xsl:otherwise>
340     </xsl:choose>
341   </xsl:if>
342 </xsl:template>
343
344 </xsl:stylesheet>