1 <?xml version="1.0" encoding="UTF-8"?>
2 <reference xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="utility">
4 <title>Common » Utility Template Reference</title>
5 <releaseinfo role="meta">
9 <partintro xml:id="partintro">
10 <title>Introduction</title>
12 <para>This is technical reference documentation for the
13 miscellaneous utility templates in the DocBook XSL
18 <para>These templates are defined in a separate file from the set
19 of “common” templates because some of the common templates
20 reference DocBook XSL stylesheet parameters, requiring the
21 entire set of parameters to be imported/included in any
22 stylesheet that imports/includes the common templates.</para>
25 <para>The utility templates don’t import or include any DocBook
26 XSL stylesheet parameters, so the utility templates can be used
27 without importing the whole set of parameters.</para>
31 <para>This is not intended to be user documentation. It is
32 provided for developers writing customization layers for the
37 <refentry xml:id="template.log.message">
39 <refname>log.message</refname>
40 <refpurpose>Logs/emits formatted notes and warnings</refpurpose>
43 <synopsis><xsl:template name="log.message">
44 <xsl:param name="level"/>
45 <xsl:param name="source"/>
46 <xsl:param name="context-desc"/>
47 <xsl:param name="context-desc-field-length">12</xsl:param>
48 <xsl:param name="context-desc-padded">
49 <xsl:if test="not($context-desc = '')">
50 <xsl:call-template name="pad-string">
51 <xsl:with-param name="leftRight">right</xsl:with-param>
52 <xsl:with-param name="padVar" select="substring($context-desc, 1, $context-desc-field-length)"/>
53 <xsl:with-param name="length" select="$context-desc-field-length"/>
54 </xsl:call-template>
57 <xsl:param name="message"/>
58 <xsl:param name="message-field-length" select="45"/>
59 <xsl:param name="message-padded">
60 <xsl:variable name="spaces-for-blank-level">
61 <!-- * if the level field is blank, we'll need to pad out -->
62 <!-- * the message field with spaces to compensate -->
64 <xsl:when test="$level = ''">
65 <xsl:value-of select="4 + 2"/>
66 <!-- * 4 = hard-coded length of comment text ("Note" or "Warn") -->
67 <!-- * + 2 = length of colon-plus-space separator ": " -->
70 <xsl:value-of select="0"/>
71 </xsl:otherwise>
74 <xsl:variable name="spaces-for-blank-context-desc">
75 <!-- * if the context-description field is blank, we'll need -->
76 <!-- * to pad out the message field with spaces to compensate -->
78 <xsl:when test="$context-desc = ''">
79 <xsl:value-of select="$context-desc-field-length + 2"/>
80 <!-- * + 2 = length of colon-plus-space separator ": " -->
83 <xsl:value-of select="0"/>
84 </xsl:otherwise>
87 <xsl:variable name="extra-spaces" select="$spaces-for-blank-level + $spaces-for-blank-context-desc"/>
88 <xsl:call-template name="pad-string">
89 <xsl:with-param name="leftRight">right</xsl:with-param>
90 <xsl:with-param name="padVar" select="substring($message, 1, ($message-field-length + $extra-spaces))"/>
91 <xsl:with-param name="length" select="$message-field-length + $extra-spaces"/>
92 </xsl:call-template>
95 </xsl:template></synopsis>
97 <refsect1><title>Description</title>
99 <para>The <function>log.message</function> template is a utility
100 template for logging/emitting formatted messages – that is,
101 notes and warnings, along with a given log “level” and an
102 identifier for the “source” that the message relates to.</para>
104 </refsect1><refsect1><title>Parameters</title>
107 <varlistentry><term>level</term>
110 <para>Text to log/emit in the message-level field to
111 indicate the message level
112 (<literal>Note</literal> or
113 <literal>Warning</literal>)</para>
117 <varlistentry><term>source</term>
120 <para>Text to log/emit in the source field to identify the
121 “source” to which the notification/warning relates.
122 This can be any arbitrary string, but because the
123 message lacks line and column numbers to identify the
124 exact part of the source document to which it
125 relates, the intention is that the value you pass
126 into the <literal>source</literal> parameter should
127 give the user some way to identify the portion of
128 their source document on which to take potentially
129 take action in response to the log message (for
130 example, to edit, change, or add content).</para>
133 <para>So the <literal>source</literal> value should be,
134 for example, an ID, book/chapter/article title, title
135 of some formal object, or even a string giving an
136 XPath expression.</para>
140 <varlistentry><term>context-desc</term>
143 <para>Text to log/emit in the context-description field to
144 describe the context for the message.</para>
148 <varlistentry><term>context-desc-field-length</term>
151 <para>Specifies length of the context-description field
152 (in characters); default is 12</para>
155 <para>If the text specified by the
156 <literal>context-desc</literal> parameter is longer
157 than the number of characters specified in
158 <literal>context-desc-field-length</literal>, it is
159 truncated to <literal>context-desc-field-length</literal>
160 (12 characters by default).</para>
163 <para>If the specified text is shorter than
164 <literal>context-desc-field-length</literal>,
165 it is right-padded out to
166 <literal>context-desc-field-length</literal> (12 by
170 <para>If no value has been specified for the
171 <literal>context-desc</literal> parameter, the field is
172 left empty and the text of the log message begins with
173 the value of the <literal>message</literal>
178 <varlistentry><term>message</term>
181 <para>Text to log/emit in the actual message field</para>
185 <varlistentry><term>message-field-length</term>
188 <para>Specifies length of the message
189 field (in characters); default is 45</para>
195 </refsect1><refsect1><title>Returns</title>
197 <para>Outputs a message (generally, to standard error).</para>
198 </refsect1></refentry>
200 <refentry xml:id="template.get.doc.title">
202 <refname>get.doc.title</refname>
203 <refpurpose>Gets a title from the current document</refpurpose>
206 <synopsis><xsl:template name="get.doc.title"/></synopsis>
208 <refsect1><title>Description</title>
210 <para>The <function>get.doc.title</function> template is a
211 utility template for returning the first title found in the
212 current document.</para>
214 </refsect1><refsect1><title>Returns</title>
216 <para>Returns a string containing some identifying title for the
217 current document .</para>
218 </refsect1></refentry>
220 <refentry xml:id="template.pad-string">
222 <refname>pad-string</refname>
223 <refpurpose>Right-pads or left-pads a string out to a certain length</refpurpose>
226 <synopsis><xsl:template name="pad-string">
227 <xsl:param name="padChar" select="' '"/>
228 <xsl:param name="leftRight">left</xsl:param>
229 <xsl:param name="padVar"/>
230 <xsl:param name="length"/>
232 </xsl:template></synopsis>
234 <refsect1><title>Description</title>
236 <para>This function takes string <parameter>padVar</parameter> and
237 pads it out in the direction <parameter>rightLeft</parameter> to
238 the string-length <parameter>length</parameter>, using string
239 <parameter>padChar</parameter> (a space character by default) as
240 the padding string (note that <parameter>padChar</parameter> can
241 be a string; it is not limited to just being a single
246 <para>This function began as a copy of Nate Austin's
247 <function>prepend-pad</function> function in the <link xlink:href="http://www.dpawson.co.uk/xsl/sect2/padding.html">Padding
248 Content</link> section of Dave Pawson's <link xlink:href="http://www.dpawson.co.uk/xsl/index.html">XSLT
252 </refsect1><refsect1><title>Returns</title>
254 <para>Returns a (padded) string.</para>
255 </refsect1></refentry>