]> git.lyx.org Git - lyx.git/blob - lib/docbook/common/utility.xsl
Use same find-dialogs as other bind-files also for x?emacs
[lyx.git] / lib / docbook / common / utility.xsl
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                 xmlns:d="http://docbook.org/ns/docbook"
4                 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
5                 xmlns:dyn="http://exslt.org/dynamic"
6                 xmlns:saxon="http://icl.com/saxon"
7                 xmlns:xlink="http://www.w3.org/1999/xlink"
8                 exclude-result-prefixes="doc dyn saxon d"
9                 version='1.0'>
10
11 <!-- ********************************************************************
12
13      This file is part of the XSL DocBook Stylesheet distribution.
14      See ../README or http://cdn.docbook.org/release/xsl/current/ for
15      copyright and other information.
16
17      ******************************************************************** -->
18 <doc:reference xmlns="" xml:id="utility">
19   <info>
20     <title>Common » Utility Template Reference</title>
21     <releaseinfo role="meta">
22     </releaseinfo>
23   </info>
24   <!-- * yes, partintro is a valid child of a reference... -->
25   <partintro xml:id="partintro">
26     <title>Introduction</title>
27     <para>This is technical reference documentation for the
28       miscellaneous utility templates in the DocBook XSL
29       Stylesheets.</para>
30     <note>
31       <para>These templates are defined in a separate file from the set
32         of “common” templates because some of the common templates
33         reference DocBook XSL stylesheet parameters, requiring the
34         entire set of parameters to be imported/included in any
35         stylesheet that imports/includes the common templates.</para>
36       <para>The utility templates don’t import or include any DocBook
37         XSL stylesheet parameters, so the utility templates can be used
38         without importing the whole set of parameters.</para>
39     </note>
40     <para>This is not intended to be user documentation. It is
41       provided for developers writing customization layers for the
42       stylesheets.</para>
43   </partintro>
44 </doc:reference>
45
46 <!-- ====================================================================== -->
47
48 <doc:template name="log.message" xmlns="">
49   <refpurpose>Logs/emits formatted notes and warnings</refpurpose>
50
51   <refdescription id="log.message-desc">
52     <para>The <function>log.message</function> template is a utility
53     template for logging/emitting formatted messages&#xa0;– that is,
54     notes and warnings, along with a given log “level” and an
55     identifier for the “source” that the message relates to.</para>
56   </refdescription>
57
58   <refparameter id="log.message-params">
59     <variablelist>
60       <varlistentry><term>level</term>
61         <listitem>
62           <para>Text to log/emit in the message-level field to
63             indicate the message level
64           (<literal>Note</literal> or
65           <literal>Warning</literal>)</para>
66         </listitem>
67       </varlistentry>
68       <varlistentry><term>source</term>
69         <listitem>
70           <para>Text to log/emit in the source field to identify the
71             “source” to which the notification/warning relates.
72             This can be any arbitrary string, but because the
73             message lacks line and column numbers to identify the
74             exact part of the source document to which it
75             relates, the intention is that the value you pass
76             into the <literal>source</literal> parameter should
77             give the user some way to identify the portion of
78             their source document on which to take potentially
79             take action in response to the log message (for
80             example, to edit, change, or add content).</para>
81           <para>So the <literal>source</literal> value should be,
82             for example, an ID, book/chapter/article title, title
83             of some formal object, or even a string giving an
84             XPath expression.</para>
85         </listitem>
86       </varlistentry>
87       <varlistentry><term>context-desc</term>
88         <listitem>
89           <para>Text to log/emit in the context-description field to
90             describe the context for the message.</para>
91         </listitem>
92       </varlistentry>
93       <varlistentry><term>context-desc-field-length</term>
94         <listitem>
95           <para>Specifies length of the context-description field
96             (in characters); default is 12</para>
97           <para>If the text specified by the
98             <literal>context-desc</literal> parameter is longer
99             than the number of characters specified in
100             <literal>context-desc-field-length</literal>, it is
101             truncated to <literal>context-desc-field-length</literal>
102             (12 characters by default).</para>
103           <para>If the specified text is shorter than
104             <literal>context-desc-field-length</literal>,
105           it is right-padded out to
106           <literal>context-desc-field-length</literal> (12 by
107           default).</para>
108         <para>If no value has been specified for the
109           <literal>context-desc</literal> parameter, the field is
110           left empty and the text of the log message begins with
111           the value of the <literal>message</literal>
112           parameter.</para>
113         </listitem>
114       </varlistentry>
115       <varlistentry><term>message</term>
116         <listitem>
117           <para>Text to log/emit in the actual message field</para>
118         </listitem>
119       </varlistentry>
120       <varlistentry><term>message-field-length</term>
121         <listitem>
122           <para>Specifies length of the message
123             field (in characters); default is 45</para>
124         </listitem>
125       </varlistentry>
126     </variablelist>
127   </refparameter>
128   <refreturn id="log.message-returns">
129   <para>Outputs a message (generally, to standard error).</para></refreturn>
130 </doc:template>
131 <xsl:template name="log.message">
132   <xsl:param name="level"/>
133   <xsl:param name="source"/>
134   <xsl:param name="context-desc"/>
135   <xsl:param name="context-desc-field-length">12</xsl:param>
136   <xsl:param name="context-desc-padded">
137     <xsl:if test="not($context-desc = '')">
138       <xsl:call-template name="pad-string">
139         <xsl:with-param name="leftRight">right</xsl:with-param>
140         <xsl:with-param name="padVar"
141           select="substring($context-desc, 1, $context-desc-field-length)"/>
142         <xsl:with-param name="length" select="$context-desc-field-length"/>
143       </xsl:call-template>
144     </xsl:if>
145   </xsl:param>
146   <xsl:param name="message"/>
147   <xsl:param name="message-field-length" select="45"/>
148   <xsl:param name="message-padded">
149     <xsl:variable name="spaces-for-blank-level">
150       <!-- * if the level field is blank, we'll need to pad out -->
151       <!-- * the message field with spaces to compensate -->
152       <xsl:choose>
153         <xsl:when test="$level = ''">
154           <xsl:value-of select="4 + 2"/>
155           <!-- * 4 = hard-coded length of comment text ("Note" or "Warn") -->
156           <!-- * + 2 = length of colon-plus-space separator ": " -->
157         </xsl:when>
158         <xsl:otherwise>
159           <xsl:value-of select="0"/>
160         </xsl:otherwise>
161       </xsl:choose>
162     </xsl:variable>
163     <xsl:variable name="spaces-for-blank-context-desc">
164       <!-- * if the context-description field is blank, we'll need -->
165       <!-- * to pad out the message field with spaces to compensate -->
166       <xsl:choose>
167         <xsl:when test="$context-desc = ''">
168           <xsl:value-of select="$context-desc-field-length + 2"/>
169           <!-- * + 2 = length of colon-plus-space separator ": " -->
170         </xsl:when>
171         <xsl:otherwise>
172           <xsl:value-of select="0"/>
173         </xsl:otherwise>
174       </xsl:choose>
175     </xsl:variable>
176     <xsl:variable name="extra-spaces"
177       select="$spaces-for-blank-level + $spaces-for-blank-context-desc"/>
178     <xsl:call-template name="pad-string">
179       <xsl:with-param name="leftRight">right</xsl:with-param>
180       <xsl:with-param name="padVar"
181         select="substring($message, 1, ($message-field-length + $extra-spaces))"/>
182       <xsl:with-param name="length"
183         select="$message-field-length + $extra-spaces"/>
184     </xsl:call-template>
185   </xsl:param>
186   <!-- * emit the actual log message -->
187   <xsl:message>
188     <xsl:if test="not($level = '')">
189       <xsl:value-of select="$level"/>
190       <xsl:text>: </xsl:text>
191     </xsl:if>
192     <xsl:if test="not($context-desc = '')">
193       <xsl:value-of select="$context-desc-padded"/>
194       <xsl:text>: </xsl:text>
195     </xsl:if>
196     <xsl:value-of select="$message-padded"/>
197     <xsl:text>  </xsl:text>
198     <xsl:value-of select="$source"/>
199   </xsl:message>
200 </xsl:template>
201
202 <!-- ===================================== -->
203 <doc:template name="get.doc.title" xmlns="">
204   <refpurpose>Gets a title from the current document</refpurpose>
205   <refdescription id="get.doc.title-desc">
206     <para>The <function>get.doc.title</function> template is a
207       utility template for returning the first title found in the
208       current document.</para>
209   </refdescription>
210   <refreturn id="get.doc.title-returns">
211   <para>Returns a string containing some identifying title for the
212     current document .</para></refreturn>
213 </doc:template>
214 <xsl:template name="get.doc.title">
215   <xsl:choose>
216     <xsl:when test="//*[local-name() = 'title'
217       or local-name() = 'refname']">
218       <xsl:value-of select="//*[local-name() = 'title'
219         or local-name() = 'refname'][1]"/>
220     </xsl:when>
221     <xsl:when test="substring(local-name(*[1]),
222       string-length(local-name(*[1])-3) = 'info')
223       and *[1]/*[local-name() = 'title']">
224       <xsl:value-of select="*[1]/*[local-name() = 'title'][1]"/>
225     </xsl:when>
226   </xsl:choose>
227 </xsl:template>
228
229 <!-- ===================================== -->
230 <doc:template name="pad-string" xmlns="">
231   <refpurpose>Right-pads or left-pads a string out to a certain length</refpurpose>
232   <refdescription id="pad-string-desc">
233     <para>This function takes string <parameter>padVar</parameter> and
234       pads it out in the direction <parameter>rightLeft</parameter> to
235       the string-length <parameter>length</parameter>, using string
236       <parameter>padChar</parameter> (a space character by default) as
237       the padding string (note that <parameter>padChar</parameter> can
238       be a string; it is not limited to just being a single
239       character).</para>
240     <note>
241       <para>This function began as a copy of Nate Austin's
242         <function>prepend-pad</function> function in the <link
243           xlink:href="http://www.dpawson.co.uk/xsl/sect2/padding.html" >Padding
244           Content</link> section of Dave Pawson's <link
245           xlink:href="http://www.dpawson.co.uk/xsl/index.html" >XSLT
246           FAQ</link>.</para>
247     </note>
248   </refdescription>
249   <refreturn id="pad-string-returns">
250   <para>Returns a (padded) string.</para></refreturn>
251 </doc:template>
252 <xsl:template name="pad-string">
253   <!-- * recursive template to right/left pad the value with -->
254   <!-- * whatever padChar is passed in -->
255   <xsl:param name="padChar" select="' '"/>
256   <xsl:param name="leftRight">left</xsl:param>
257   <xsl:param name="padVar"/>
258   <xsl:param name="length"/>
259   <xsl:choose>
260     <xsl:when test="string-length($padVar) &lt; $length">
261       <xsl:call-template name="pad-string">
262         <xsl:with-param name="padChar" select="$padChar"/>
263         <xsl:with-param name="leftRight" select="$leftRight"/>
264         <xsl:with-param name="padVar">
265           <xsl:choose>
266             <!-- * determine whether string should be -->
267             <!-- * right- or left-padded -->
268             <xsl:when test="$leftRight = 'left'">
269               <!-- * pad it to left -->
270               <xsl:value-of select="concat($padChar,$padVar)"/>
271             </xsl:when>
272             <xsl:otherwise>
273               <!-- * otherwise, right-pad the string -->
274               <xsl:value-of select="concat($padVar,$padChar)"/>
275             </xsl:otherwise>
276           </xsl:choose>
277         </xsl:with-param>
278         <xsl:with-param name="length" select="$length"/>
279       </xsl:call-template>
280     </xsl:when>
281     <xsl:otherwise>
282       <xsl:value-of 
283         select="substring($padVar,string-length($padVar) - $length + 1)"/>
284     </xsl:otherwise>
285   </xsl:choose>
286 </xsl:template>
287
288 </xsl:stylesheet>