3 <reference xml:id="base">
5 <title>Common » Base Template Reference</title>
6 <releaseinfo role="meta">
7 $Id: common.xsl 8784 2010-07-28 12:32:54Z mzjn $
11 <partintro xml:id="partintro">
12 <title>Introduction</title>
14 <para>This is technical reference documentation for the “base”
15 set of common templates in the DocBook XSL Stylesheets.</para>
18 <para>This is not intended to be user documentation. It is
19 provided for developers writing customization layers for the
24 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.is.component">
26 <refname>is.component</refname>
27 <refpurpose>Tests if a given node is a component-level element</refpurpose>
30 <synopsis><xsl:template name="is.component">
31 <xsl:param name="node" select="."/>
33 </xsl:template></synopsis>
35 <refsect1><title>Description</title>
37 <para>This template returns '1' if the specified node is a component
38 (Chapter, Appendix, etc.), and '0' otherwise.</para>
40 </refsect1><refsect1><title>Parameters</title>
43 <varlistentry><term>node</term>
46 <para>The node which is to be tested.</para>
52 </refsect1><refsect1><title>Returns</title>
54 <para>This template returns '1' if the specified node is a component
55 (Chapter, Appendix, etc.), and '0' otherwise.</para>
57 </refsect1></refentry>
59 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.is.section">
61 <refname>is.section</refname>
62 <refpurpose>Tests if a given node is a section-level element</refpurpose>
65 <synopsis><xsl:template name="is.section">
66 <xsl:param name="node" select="."/>
68 </xsl:template></synopsis>
70 <refsect1><title>Description</title>
72 <para>This template returns '1' if the specified node is a section
73 (Section, Sect1, Sect2, etc.), and '0' otherwise.</para>
75 </refsect1><refsect1><title>Parameters</title>
78 <varlistentry><term>node</term>
81 <para>The node which is to be tested.</para>
87 </refsect1><refsect1><title>Returns</title>
89 <para>This template returns '1' if the specified node is a section
90 (Section, Sect1, Sect2, etc.), and '0' otherwise.</para>
92 </refsect1></refentry>
94 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.section.level">
96 <refname>section.level</refname>
97 <refpurpose>Returns the hierarchical level of a section</refpurpose>
100 <synopsis><xsl:template name="section.level">
101 <xsl:param name="node" select="."/>
103 </xsl:template></synopsis>
105 <refsect1><title>Description</title>
107 <para>This template calculates the hierarchical level of a section.
108 The element <tag>sect1</tag> is at level 1, <tag>sect2</tag> is
109 at level 2, etc.</para>
113 <para>Recursive sections are calculated down to the fifth level.</para>
115 </refsect1><refsect1><title>Parameters</title>
118 <varlistentry><term>node</term>
121 <para>The section node for which the level should be calculated.
122 Defaults to the context node.</para>
128 </refsect1><refsect1><title>Returns</title>
130 <para>The section level, <quote>1</quote>, <quote>2</quote>, etc.
133 </refsect1></refentry>
135 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.qanda.section.level">
137 <refname>qanda.section.level</refname>
138 <refpurpose>Returns the hierarchical level of a QandASet</refpurpose>
141 <synopsis><xsl:template name="qanda.section.level"/></synopsis>
143 <refsect1><title>Description</title>
145 <para>This template calculates the hierarchical level of a QandASet.
148 </refsect1><refsect1><title>Returns</title>
150 <para>The level, <quote>1</quote>, <quote>2</quote>, etc.
153 </refsect1></refentry>
155 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.select.mediaobject">
157 <refname>select.mediaobject</refname>
158 <refpurpose>Selects and processes an appropriate media object from a list</refpurpose>
161 <synopsis><xsl:template name="select.mediaobject">
162 <xsl:param name="olist" select="imageobject|imageobjectco |videoobject|audioobject|textobject"/>
164 </xsl:template></synopsis>
166 <refsect1><title>Description</title>
168 <para>This template takes a list of media objects (usually the
169 children of a mediaobject or inlinemediaobject) and processes
170 the "right" object.</para>
174 <para>This template relies on a template named
175 "select.mediaobject.index" to determine which object
176 in the list is appropriate.</para>
180 <para>If no acceptable object is located, nothing happens.</para>
182 </refsect1><refsect1><title>Parameters</title>
185 <varlistentry><term>olist</term>
188 <para>The node list of potential objects to examine.</para>
194 </refsect1><refsect1><title>Returns</title>
196 <para>Calls <xsl:apply-templates> on the selected object.</para>
198 </refsect1></refentry>
200 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.select.mediaobject.index">
202 <refname>select.mediaobject.index</refname>
203 <refpurpose>Selects the position of the appropriate media object from a list</refpurpose>
206 <synopsis><xsl:template name="select.mediaobject.index">
207 <xsl:param name="olist" select="imageobject|imageobjectco |videoobject|audioobject|textobject"/>
208 <xsl:param name="count">1</xsl:param>
210 </xsl:template></synopsis>
212 <refsect1><title>Description</title>
214 <para>This template takes a list of media objects (usually the
215 children of a mediaobject or inlinemediaobject) and determines
216 the "right" object. It returns the position of that object
217 to be used by the calling template.</para>
221 <para>If the parameter <parameter>use.role.for.mediaobject</parameter>
222 is nonzero, then it first checks for an object with
223 a role attribute of the appropriate value. It takes the first
224 of those. Otherwise, it takes the first acceptable object
225 through a recursive pass through the list.</para>
229 <para>This template relies on a template named "is.acceptable.mediaobject"
230 to determine if a given object is an acceptable graphic. The semantics
231 of media objects is that the first acceptable graphic should be used.
236 <para>If no acceptable object is located, no index is returned.</para>
238 </refsect1><refsect1><title>Parameters</title>
241 <varlistentry><term>olist</term>
244 <para>The node list of potential objects to examine.</para>
248 <varlistentry><term>count</term>
251 <para>The position in the list currently being considered by the
252 recursive process.</para>
258 </refsect1><refsect1><title>Returns</title>
260 <para>Returns the position in the original list of the selected object.</para>
262 </refsect1></refentry>
264 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.is.acceptable.mediaobject">
266 <refname>is.acceptable.mediaobject</refname>
267 <refpurpose>Returns '1' if the specified media object is recognized</refpurpose>
270 <synopsis><xsl:template name="is.acceptable.mediaobject">
271 <xsl:param name="object"/>
273 </xsl:template></synopsis>
275 <refsect1><title>Description</title>
277 <para>This template examines a media object and returns '1' if the
278 object is recognized as a graphic.</para>
280 </refsect1><refsect1><title>Parameters</title>
283 <varlistentry><term>object</term>
286 <para>The media object to consider.</para>
292 </refsect1><refsect1><title>Returns</title>
296 </refsect1></refentry>
298 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.check.id.unique">
300 <refname>check.id.unique</refname>
301 <refpurpose>Warn users about references to non-unique IDs</refpurpose>
304 <synopsis><xsl:template name="check.id.unique">
305 <xsl:param name="linkend"/>
307 </xsl:template></synopsis>
309 <refsect1><title>Description</title>
311 <para>If passed an ID in <varname>linkend</varname>,
312 <function>check.id.unique</function> prints
313 a warning message to the user if either the ID does not exist or
314 the ID is not unique.</para>
316 </refsect1></refentry>
318 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.check.idref.targets">
320 <refname>check.idref.targets</refname>
321 <refpurpose>Warn users about incorrectly typed references</refpurpose>
324 <synopsis><xsl:template name="check.idref.targets">
325 <xsl:param name="linkend"/>
326 <xsl:param name="element-list"/>
328 </xsl:template></synopsis>
330 <refsect1><title>Description</title>
332 <para>If passed an ID in <varname>linkend</varname>,
333 <function>check.idref.targets</function> makes sure that the element
334 pointed to by the link is one of the elements listed in
335 <varname>element-list</varname> and warns the user otherwise.</para>
337 </refsect1></refentry>
339 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.copyright.years">
341 <refname>copyright.years</refname>
342 <refpurpose>Print a set of years with collapsed ranges</refpurpose>
345 <synopsis><xsl:template name="copyright.years">
346 <xsl:param name="years"/>
347 <xsl:param name="print.ranges" select="1"/>
348 <xsl:param name="single.year.ranges" select="0"/>
349 <xsl:param name="firstyear" select="0"/>
350 <xsl:param name="nextyear" select="0"/>
352 </xsl:template></synopsis>
354 <refsect1><title>Description</title>
356 <para>This template prints a list of year elements with consecutive
357 years printed as a range. In other words:</para>
360 <screen><year>1992</year>
361 <year>1993</year>
362 <year>1994</year></screen>
365 <para>is printed <quote>1992-1994</quote>, whereas:</para>
368 <screen><year>1992</year>
369 <year>1994</year></screen>
372 <para>is printed <quote>1992, 1994</quote>.</para>
376 <para>This template assumes that all the year elements contain only
377 decimal year numbers, that the elements are sorted in increasing
378 numerical order, that there are no duplicates, and that all the years
379 are expressed in full <quote>century+year</quote>
380 (<quote>1999</quote> not <quote>99</quote>) notation.</para>
382 </refsect1><refsect1><title>Parameters</title>
385 <varlistentry><term>years</term>
388 <para>The initial set of year elements.</para>
392 <varlistentry><term>print.ranges</term>
395 <para>If non-zero, multi-year ranges are collapsed. If zero, all years
396 are printed discretely.</para>
400 <varlistentry><term>single.year.ranges</term>
403 <para>If non-zero, two consecutive years will be printed as a range,
404 otherwise, they will be printed discretely. In other words, a single
405 year range is <quote>1991-1992</quote> but discretely it's
406 <quote>1991, 1992</quote>.</para>
412 </refsect1><refsect1><title>Returns</title>
414 <para>This template returns the formatted list of years.</para>
416 </refsect1></refentry>
418 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.find.path.params">
420 <refname>find.path.params</refname>
421 <refpurpose>Search in a table for the "best" match for the node</refpurpose>
424 <synopsis><xsl:template name="find.path.params">
425 <xsl:param name="node" select="."/>
426 <xsl:param name="table" select="''"/>
427 <xsl:param name="location">
428 <xsl:call-template name="xpath.location">
429 <xsl:with-param name="node" select="$node"/>
430 </xsl:call-template>
433 </xsl:template></synopsis>
435 <refsect1><title>Description</title>
437 <para>This template searches in a table for the value that most-closely
438 (in the typical best-match sense of XSLT) matches the current (element)
439 node location.</para>
441 </refsect1></refentry>
443 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.string.upper">
445 <refname>string.upper</refname>
446 <refpurpose>Converts a string to all uppercase letters</refpurpose>
449 <synopsis><xsl:template name="string.upper">
450 <xsl:param name="string" select="''"/>
452 </xsl:template></synopsis>
454 <refsect1><title>Description</title>
456 <para>Given a string, this template does a language-aware conversion
457 of that string to all uppercase letters, based on the values of the
458 <literal>lowercase.alpha</literal> and
459 <literal>uppercase.alpha</literal> gentext keys for the current
460 locale. It affects only those characters found in the values of
461 <literal>lowercase.alpha</literal> and
462 <literal>uppercase.alpha</literal>. All other characters are left
465 </refsect1><refsect1><title>Parameters</title>
468 <varlistentry><term>string</term>
471 <para>The string to convert to uppercase.</para>
477 </refsect1></refentry>
479 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.string.lower">
481 <refname>string.lower</refname>
482 <refpurpose>Converts a string to all lowercase letters</refpurpose>
485 <synopsis><xsl:template name="string.lower">
486 <xsl:param name="string" select="''"/>
488 </xsl:template></synopsis>
490 <refsect1><title>Description</title>
492 <para>Given a string, this template does a language-aware conversion
493 of that string to all lowercase letters, based on the values of the
494 <literal>uppercase.alpha</literal> and
495 <literal>lowercase.alpha</literal> gentext keys for the current
496 locale. It affects only those characters found in the values of
497 <literal>uppercase.alpha</literal> and
498 <literal>lowercase.alpha</literal>. All other characters are left
501 </refsect1><refsect1><title>Parameters</title>
504 <varlistentry><term>string</term>
507 <para>The string to convert to lowercase.</para>
513 </refsect1></refentry>
515 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.select.choice.separator">
517 <refname>select.choice.separator</refname>
518 <refpurpose>Returns localized choice separator</refpurpose>
521 <synopsis><xsl:template name="select.choice.separator"/></synopsis>
523 <refsect1><title>Description</title>
525 <para>This template enables auto-generation of an appropriate
526 localized "choice" separator (for example, "and" or "or") before
527 the final item in an inline list (though it could also be useful
528 for generating choice separators for non-inline lists).</para>
531 <para>It currently works by evaluating a processing instruction
532 (PI) of the form <?dbchoice choice="foo"?> :
536 <simpara>if the value of the <tag>choice</tag>
537 pseudo-attribute is "and" or "or", returns a localized "and"
541 <simpara>otherwise returns the literal value of the
542 <tag>choice</tag> pseudo-attribute</simpara>
546 The latter is provided only as a temporary workaround because the
547 locale files do not currently have translations for the word
548 <wordasword>or</wordasword>. So if you want to generate a a
549 logical "or" separator in French (for example), you currently need
551 <literallayout><?dbchoice choice="ou"?></literallayout>
556 <para>The <tag>dbchoice</tag> processing instruction is
557 an unfortunate hack; support for it may disappear in the future
558 (particularly if and when a more appropriate means for marking
559 up "choice" lists becomes available in DocBook).</para>
562 </refsect1></refentry>
564 <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.evaluate.info.profile">
566 <refname>evaluate.info.profile</refname>
567 <refpurpose>Evaluates an info profile</refpurpose>
570 <synopsis><xsl:template name="evaluate.info.profile">
571 <xsl:param name="profile"/>
572 <xsl:param name="info"/>
574 </xsl:template></synopsis>
576 <refsect1><title>Description</title>
578 <para>This template evaluates an "info profile" matching the XPath
579 expression given by the <parameter>profile</parameter>
580 parameter. It relies on the XSLT <function>evaluate()</function>
581 extension function.</para>
585 <para>The value of the <parameter>profile</parameter> parameter
586 can include the literal string <literal>$info</literal>. If found
587 in the value of the <parameter>profile</parameter> parameter, the
588 literal string <literal>$info</literal> string is replaced with
589 the value of the <parameter>info</parameter> parameter, which
590 should be a set of <replaceable>*info</replaceable> nodes; the
591 expression is then evaluated using the XSLT
592 <function>evaluate()</function> extension function.</para>
594 </refsect1><refsect1><title>Parameters</title>
601 <para>A string representing an XPath expression </para>
609 <para>A set of *info nodes</para>
615 </refsect1><refsect1><title>Returns</title>
617 <para>Returns a node (the result of evaluating the
618 <parameter>profile</parameter> parameter)</para>
620 </refsect1></refentry>