3 <reference xml:id="utility">
5 <title>Common » Utility Template Reference</title>
6 <releaseinfo role="meta">
7 $Id: utility.xsl 7101 2007-07-20 15:32:12Z xmldoc $
11 <partintro xml:id="partintro">
12 <title>Introduction</title>
14 <para>This is technical reference documentation for the
15 miscellaneous utility templates in the DocBook XSL
20 <para>These templates are defined in a separate file from the set
21 of “common” templates because some of the common templates
22 reference DocBook XSL stylesheet parameters, requiring the
23 entire set of parameters to be imported/included in any
24 stylesheet that imports/includes the common templates.</para>
27 <para>The utility templates don’t import or include any DocBook
28 XSL stylesheet parameters, so the utility templates can be used
29 without importing the whole set of parameters.</para>
33 <para>This is not intended to be user documentation. It is
34 provided for developers writing customization layers for the
39 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.log.message">
41 <refname>log.message</refname>
42 <refpurpose>Logs/emits formatted notes and warnings</refpurpose>
45 <synopsis><xsl:template name="log.message">
46 <xsl:param name="level"/>
47 <xsl:param name="source"/>
48 <xsl:param name="context-desc"/>
49 <xsl:param name="context-desc-field-length">12</xsl:param>
50 <xsl:param name="context-desc-padded">
51 <xsl:if test="not($context-desc = '')">
52 <xsl:call-template name="pad-string">
53 <xsl:with-param name="leftRight">right</xsl:with-param>
54 <xsl:with-param name="padVar" select="substring($context-desc, 1, $context-desc-field-length)"/>
55 <xsl:with-param name="length" select="$context-desc-field-length"/>
56 </xsl:call-template>
59 <xsl:param name="message"/>
60 <xsl:param name="message-field-length" select="45"/>
61 <xsl:param name="message-padded">
62 <xsl:variable name="spaces-for-blank-level">
63 <!-- * if the level field is blank, we'll need to pad out -->
64 <!-- * the message field with spaces to compensate -->
66 <xsl:when test="$level = ''">
67 <xsl:value-of select="4 + 2"/>
68 <!-- * 4 = hard-coded length of comment text ("Note" or "Warn") -->
69 <!-- * + 2 = length of colon-plus-space separator ": " -->
72 <xsl:value-of select="0"/>
73 </xsl:otherwise>
76 <xsl:variable name="spaces-for-blank-context-desc">
77 <!-- * if the context-description field is blank, we'll need -->
78 <!-- * to pad out the message field with spaces to compensate -->
80 <xsl:when test="$context-desc = ''">
81 <xsl:value-of select="$context-desc-field-length + 2"/>
82 <!-- * + 2 = length of colon-plus-space separator ": " -->
85 <xsl:value-of select="0"/>
86 </xsl:otherwise>
89 <xsl:variable name="extra-spaces" select="$spaces-for-blank-level + $spaces-for-blank-context-desc"/>
90 <xsl:call-template name="pad-string">
91 <xsl:with-param name="leftRight">right</xsl:with-param>
92 <xsl:with-param name="padVar" select="substring($message, 1, ($message-field-length + $extra-spaces))"/>
93 <xsl:with-param name="length" select="$message-field-length + $extra-spaces"/>
94 </xsl:call-template>
97 </xsl:template></synopsis>
99 <refsect1><title>Description</title>
101 <para>The <function>log.message</function> template is a utility
102 template for logging/emitting formatted messages – that is,
103 notes and warnings, along with a given log “level” and an
104 identifier for the “source” that the message relates to.</para>
106 </refsect1><refsect1><title>Parameters</title>
109 <varlistentry><term>level</term>
112 <para>Text to log/emit in the message-level field to
113 indicate the message level
114 (<literal>Note</literal> or
115 <literal>Warning</literal>)</para>
119 <varlistentry><term>source</term>
122 <para>Text to log/emit in the source field to identify the
123 “source” to which the notification/warning relates.
124 This can be any arbitrary string, but because the
125 message lacks line and column numbers to identify the
126 exact part of the source document to which it
127 relates, the intention is that the value you pass
128 into the <literal>source</literal> parameter should
129 give the user some way to identify the portion of
130 their source document on which to take potentially
131 take action in response to the log message (for
132 example, to edit, change, or add content).</para>
135 <para>So the <literal>source</literal> value should be,
136 for example, an ID, book/chapter/article title, title
137 of some formal object, or even a string giving an
138 XPath expression.</para>
142 <varlistentry><term>context-desc</term>
145 <para>Text to log/emit in the context-description field to
146 describe the context for the message.</para>
150 <varlistentry><term>context-desc-field-length</term>
153 <para>Specifies length of the context-description field
154 (in characters); default is 12</para>
157 <para>If the text specified by the
158 <literal>context-desc</literal> parameter is longer
159 than the number of characters specified in
160 <literal>context-desc-field-length</literal>, it is
161 truncated to <literal>context-desc-field-length</literal>
162 (12 characters by default).</para>
165 <para>If the specified text is shorter than
166 <literal>context-desc-field-length</literal>,
167 it is right-padded out to
168 <literal>context-desc-field-length</literal> (12 by
172 <para>If no value has been specified for the
173 <literal>context-desc</literal> parameter, the field is
174 left empty and the text of the log message begins with
175 the value of the <literal>message</literal>
180 <varlistentry><term>message</term>
183 <para>Text to log/emit in the actual message field</para>
187 <varlistentry><term>message-field-length</term>
190 <para>Specifies length of the message
191 field (in characters); default is 45</para>
197 </refsect1><refsect1><title>Returns</title>
199 <para>Outputs a message (generally, to standard error).</para>
200 </refsect1></refentry>
202 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.get.doc.title">
204 <refname>get.doc.title</refname>
205 <refpurpose>Gets a title from the current document</refpurpose>
208 <synopsis><xsl:template name="get.doc.title"/></synopsis>
210 <refsect1><title>Description</title>
212 <para>The <function>get.doc.title</function> template is a
213 utility template for returning the first title found in the
214 current document.</para>
216 </refsect1><refsect1><title>Returns</title>
218 <para>Returns a string containing some identifying title for the
219 current document .</para>
220 </refsect1></refentry>
222 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.pad-string">
224 <refname>pad-string</refname>
225 <refpurpose>Right-pads or left-pads a string out to a certain length</refpurpose>
228 <synopsis><xsl:template name="pad-string">
229 <xsl:param name="padChar" select="' '"/>
230 <xsl:param name="leftRight">left</xsl:param>
231 <xsl:param name="padVar"/>
232 <xsl:param name="length"/>
234 </xsl:template></synopsis>
236 <refsect1><title>Description</title>
238 <para>This function takes string <parameter>padVar</parameter> and
239 pads it out in the direction <parameter>rightLeft</parameter> to
240 the string-length <parameter>length</parameter>, using string
241 <parameter>padChar</parameter> (a space character by default) as
242 the padding string (note that <parameter>padChar</parameter> can
243 be a string; it is not limited to just being a single
248 <para>This function began as a copy of Nate Austin's
249 <function>prepend-pad</function> function in the <link xlink:href="http://www.dpawson.co.uk/xsl/sect2/padding.html">Padding
250 Content</link> section of Dave Pawson's <link xlink:href="http://www.dpawson.co.uk/xsl/index.html">XSLT
254 </refsect1><refsect1><title>Returns</title>
256 <para>Returns a (padded) string.</para>
257 </refsect1></refentry>