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