utility.xml 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?xml version="1.0"?>
  2. <reference xml:id="utility">
  3. <info>
  4. <title>Common » Utility Template Reference</title>
  5. <releaseinfo role="meta">
  6. $Id: utility.xsl 7101 2007-07-20 15:32:12Z xmldoc $
  7. </releaseinfo>
  8. </info>
  9. <partintro xml:id="partintro">
  10. <title>Introduction</title>
  11. <para>This is technical reference documentation for the
  12. miscellaneous utility templates in the DocBook XSL
  13. Stylesheets.</para>
  14. <note>
  15. <para>These templates are defined in a separate file from the set
  16. of “common” templates because some of the common templates
  17. reference DocBook XSL stylesheet parameters, requiring the
  18. entire set of parameters to be imported/included in any
  19. stylesheet that imports/includes the common templates.</para>
  20. <para>The utility templates don’t import or include any DocBook
  21. XSL stylesheet parameters, so the utility templates can be used
  22. without importing the whole set of parameters.</para>
  23. </note>
  24. <para>This is not intended to be user documentation. It is
  25. provided for developers writing customization layers for the
  26. stylesheets.</para>
  27. </partintro>
  28. <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.log.message">
  29. <refnamediv>
  30. <refname>log.message</refname>
  31. <refpurpose>Logs/emits formatted notes and warnings</refpurpose>
  32. </refnamediv>
  33. <refsynopsisdiv>
  34. <synopsis>&lt;xsl:template name="log.message"&gt;
  35. &lt;xsl:param name="level"/&gt;
  36. &lt;xsl:param name="source"/&gt;
  37. &lt;xsl:param name="context-desc"/&gt;
  38. &lt;xsl:param name="context-desc-field-length"&gt;12&lt;/xsl:param&gt;
  39. &lt;xsl:param name="context-desc-padded"&gt;
  40. &lt;xsl:if test="not($context-desc = '')"&gt;
  41. &lt;xsl:call-template name="pad-string"&gt;
  42. &lt;xsl:with-param name="leftRight"&gt;right&lt;/xsl:with-param&gt;
  43. &lt;xsl:with-param name="padVar" select="substring($context-desc, 1, $context-desc-field-length)"/&gt;
  44. &lt;xsl:with-param name="length" select="$context-desc-field-length"/&gt;
  45. &lt;/xsl:call-template&gt;
  46. &lt;/xsl:if&gt;
  47. &lt;/xsl:param&gt;
  48. &lt;xsl:param name="message"/&gt;
  49. &lt;xsl:param name="message-field-length" select="45"/&gt;
  50. &lt;xsl:param name="message-padded"&gt;
  51. &lt;xsl:variable name="spaces-for-blank-level"&gt;
  52. &lt;!-- * if the level field is blank, we'll need to pad out --&gt;
  53. &lt;!-- * the message field with spaces to compensate --&gt;
  54. &lt;xsl:choose&gt;
  55. &lt;xsl:when test="$level = ''"&gt;
  56. &lt;xsl:value-of select="4 + 2"/&gt;
  57. &lt;!-- * 4 = hard-coded length of comment text ("Note" or "Warn") --&gt;
  58. &lt;!-- * + 2 = length of colon-plus-space separator ": " --&gt;
  59. &lt;/xsl:when&gt;
  60. &lt;xsl:otherwise&gt;
  61. &lt;xsl:value-of select="0"/&gt;
  62. &lt;/xsl:otherwise&gt;
  63. &lt;/xsl:choose&gt;
  64. &lt;/xsl:variable&gt;
  65. &lt;xsl:variable name="spaces-for-blank-context-desc"&gt;
  66. &lt;!-- * if the context-description field is blank, we'll need --&gt;
  67. &lt;!-- * to pad out the message field with spaces to compensate --&gt;
  68. &lt;xsl:choose&gt;
  69. &lt;xsl:when test="$context-desc = ''"&gt;
  70. &lt;xsl:value-of select="$context-desc-field-length + 2"/&gt;
  71. &lt;!-- * + 2 = length of colon-plus-space separator ": " --&gt;
  72. &lt;/xsl:when&gt;
  73. &lt;xsl:otherwise&gt;
  74. &lt;xsl:value-of select="0"/&gt;
  75. &lt;/xsl:otherwise&gt;
  76. &lt;/xsl:choose&gt;
  77. &lt;/xsl:variable&gt;
  78. &lt;xsl:variable name="extra-spaces" select="$spaces-for-blank-level + $spaces-for-blank-context-desc"/&gt;
  79. &lt;xsl:call-template name="pad-string"&gt;
  80. &lt;xsl:with-param name="leftRight"&gt;right&lt;/xsl:with-param&gt;
  81. &lt;xsl:with-param name="padVar" select="substring($message, 1, ($message-field-length + $extra-spaces))"/&gt;
  82. &lt;xsl:with-param name="length" select="$message-field-length + $extra-spaces"/&gt;
  83. &lt;/xsl:call-template&gt;
  84. &lt;/xsl:param&gt;
  85. ...
  86. &lt;/xsl:template&gt;</synopsis>
  87. </refsynopsisdiv>
  88. <refsect1><title>Description</title>
  89. <para>The <function>log.message</function> template is a utility
  90. template for logging/emitting formatted messages – that is,
  91. notes and warnings, along with a given log “level” and an
  92. identifier for the “source” that the message relates to.</para>
  93. </refsect1><refsect1><title>Parameters</title>
  94. <variablelist>
  95. <varlistentry><term>level</term>
  96. <listitem>
  97. <para>Text to log/emit in the message-level field to
  98. indicate the message level
  99. (<literal>Note</literal> or
  100. <literal>Warning</literal>)</para>
  101. </listitem>
  102. </varlistentry>
  103. <varlistentry><term>source</term>
  104. <listitem>
  105. <para>Text to log/emit in the source field to identify the
  106. “source” to which the notification/warning relates.
  107. This can be any arbitrary string, but because the
  108. message lacks line and column numbers to identify the
  109. exact part of the source document to which it
  110. relates, the intention is that the value you pass
  111. into the <literal>source</literal> parameter should
  112. give the user some way to identify the portion of
  113. their source document on which to take potentially
  114. take action in response to the log message (for
  115. example, to edit, change, or add content).</para>
  116. <para>So the <literal>source</literal> value should be,
  117. for example, an ID, book/chapter/article title, title
  118. of some formal object, or even a string giving an
  119. XPath expression.</para>
  120. </listitem>
  121. </varlistentry>
  122. <varlistentry><term>context-desc</term>
  123. <listitem>
  124. <para>Text to log/emit in the context-description field to
  125. describe the context for the message.</para>
  126. </listitem>
  127. </varlistentry>
  128. <varlistentry><term>context-desc-field-length</term>
  129. <listitem>
  130. <para>Specifies length of the context-description field
  131. (in characters); default is 12</para>
  132. <para>If the text specified by the
  133. <literal>context-desc</literal> parameter is longer
  134. than the number of characters specified in
  135. <literal>context-desc-field-length</literal>, it is
  136. truncated to <literal>context-desc-field-length</literal>
  137. (12 characters by default).</para>
  138. <para>If the specified text is shorter than
  139. <literal>context-desc-field-length</literal>,
  140. it is right-padded out to
  141. <literal>context-desc-field-length</literal> (12 by
  142. default).</para>
  143. <para>If no value has been specified for the
  144. <literal>context-desc</literal> parameter, the field is
  145. left empty and the text of the log message begins with
  146. the value of the <literal>message</literal>
  147. parameter.</para>
  148. </listitem>
  149. </varlistentry>
  150. <varlistentry><term>message</term>
  151. <listitem>
  152. <para>Text to log/emit in the actual message field</para>
  153. </listitem>
  154. </varlistentry>
  155. <varlistentry><term>message-field-length</term>
  156. <listitem>
  157. <para>Specifies length of the message
  158. field (in characters); default is 45</para>
  159. </listitem>
  160. </varlistentry>
  161. </variablelist>
  162. </refsect1><refsect1><title>Returns</title>
  163. <para>Outputs a message (generally, to standard error).</para>
  164. </refsect1></refentry>
  165. <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.get.doc.title">
  166. <refnamediv>
  167. <refname>get.doc.title</refname>
  168. <refpurpose>Gets a title from the current document</refpurpose>
  169. </refnamediv>
  170. <refsynopsisdiv>
  171. <synopsis>&lt;xsl:template name="get.doc.title"/&gt;</synopsis>
  172. </refsynopsisdiv>
  173. <refsect1><title>Description</title>
  174. <para>The <function>get.doc.title</function> template is a
  175. utility template for returning the first title found in the
  176. current document.</para>
  177. </refsect1><refsect1><title>Returns</title>
  178. <para>Returns a string containing some identifying title for the
  179. current document .</para>
  180. </refsect1></refentry>
  181. <refentry xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="template.pad-string">
  182. <refnamediv>
  183. <refname>pad-string</refname>
  184. <refpurpose>Right-pads or left-pads a string out to a certain length</refpurpose>
  185. </refnamediv>
  186. <refsynopsisdiv>
  187. <synopsis>&lt;xsl:template name="pad-string"&gt;
  188. &lt;xsl:param name="padChar" select="' '"/&gt;
  189. &lt;xsl:param name="leftRight"&gt;left&lt;/xsl:param&gt;
  190. &lt;xsl:param name="padVar"/&gt;
  191. &lt;xsl:param name="length"/&gt;
  192. ...
  193. &lt;/xsl:template&gt;</synopsis>
  194. </refsynopsisdiv>
  195. <refsect1><title>Description</title>
  196. <para>This function takes string <parameter>padVar</parameter> and
  197. pads it out in the direction <parameter>rightLeft</parameter> to
  198. the string-length <parameter>length</parameter>, using string
  199. <parameter>padChar</parameter> (a space character by default) as
  200. the padding string (note that <parameter>padChar</parameter> can
  201. be a string; it is not limited to just being a single
  202. character).</para>
  203. <note>
  204. <para>This function began as a copy of Nate Austin's
  205. <function>prepend-pad</function> function in the <link xlink:href="http://www.dpawson.co.uk/xsl/sect2/padding.html">Padding
  206. Content</link> section of Dave Pawson's <link xlink:href="http://www.dpawson.co.uk/xsl/index.html">XSLT
  207. FAQ</link>.</para>
  208. </note>
  209. </refsect1><refsect1><title>Returns</title>
  210. <para>Returns a (padded) string.</para>
  211. </refsect1></refentry>
  212. </reference>