pi.xsl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
  5. xmlns:date="http://exslt.org/dates-and-times"
  6. xmlns:exsl="http://exslt.org/common"
  7. xmlns:xlink="http://www.w3.org/1999/xlink"
  8. exclude-result-prefixes="doc date exsl"
  9. extension-element-prefixes="date exsl"
  10. version='1.0'>
  11. <!-- ********************************************************************
  12. $Id$
  13. ********************************************************************
  14. This file is part of the XSL DocBook Stylesheet distribution.
  15. See ../README or http://docbook.sf.net/release/xsl/current/ for
  16. copyright and other information.
  17. ******************************************************************** -->
  18. <doc:reference xmlns=""><info><title>Common Processing Instruction Reference</title>
  19. <releaseinfo role="meta">
  20. $Id$
  21. </releaseinfo>
  22. </info>
  23. <partintro id="partintro">
  24. <title>Introduction</title>
  25. <para>This is generated reference documentation for all
  26. user-specifiable processing instructions (PIs) in the
  27. “common” part of the DocBook XSL stylesheets.
  28. <note>
  29. <para>You add these PIs at particular points in a document to
  30. cause specific “exceptions” to formatting/output behavior. To
  31. make global changes in formatting/output behavior across an
  32. entire document, it’s better to do it by setting an
  33. appropriate stylesheet parameter (if there is one).</para>
  34. </note>
  35. </para>
  36. </partintro>
  37. </doc:reference>
  38. <!-- ==================================================================== -->
  39. <doc:pi name="dbchoice_choice" xmlns="">
  40. <refpurpose>Generates a localized choice separator</refpurpose>
  41. <refdescription id="select.choice.separator-desc">
  42. <para>Use the <tag class="xmlpi">dbchoice choice</tag> PI to
  43. generate an appropriate localized “choice” separator (for
  44. example, <literal>and</literal> or <literal>or</literal>)
  45. before the final item in an inline <tag>simplelist</tag></para>
  46. <warning>
  47. <para>This PI is a less-than-ideal hack; support for it may
  48. disappear in the future (particularly if and when a more
  49. appropriate means for marking up "choice" lists becomes
  50. available in DocBook).</para>
  51. </warning>
  52. </refdescription>
  53. <refsynopsisdiv>
  54. <synopsis><tag class="xmlpi">dbchoice choice="and"|"or"|<replaceable>string</replaceable>"</tag></synopsis>
  55. </refsynopsisdiv>
  56. <refparameter>
  57. <variablelist>
  58. <varlistentry><term>choice="and"</term>
  59. <listitem>
  60. <para>generates a localized <literal>and</literal> separator</para>
  61. </listitem>
  62. </varlistentry>
  63. <varlistentry><term>choice="or"</term>
  64. <listitem>
  65. <para>generates a localized <literal>or</literal> separator</para>
  66. </listitem>
  67. </varlistentry>
  68. <varlistentry><term>choice="<replaceable>string</replaceable>"</term>
  69. <listitem>
  70. <para>generates a literal <replaceable>string</replaceable> separator</para>
  71. </listitem>
  72. </varlistentry>
  73. </variablelist>
  74. </refparameter>
  75. </doc:pi>
  76. <xsl:template name="pi.dbchoice_choice">
  77. <xsl:param name="node" select="."/>
  78. <xsl:call-template name="pi-attribute">
  79. <xsl:with-param name="pis" select="$node/processing-instruction('dbchoice')"/>
  80. <xsl:with-param name="attribute">choice</xsl:with-param>
  81. </xsl:call-template>
  82. </xsl:template>
  83. <doc:pi name="dbtimestamp" xmlns="">
  84. <refpurpose>Inserts a date timestamp</refpurpose>
  85. <refdescription>
  86. <para>Use the <tag class="xmlpi">dbtimestamp</tag> PI at any point in a
  87. source document to cause a date timestamp (a formatted
  88. string representing the current date and time) to be
  89. inserted in output of the document.</para>
  90. </refdescription>
  91. <refsynopsisdiv>
  92. <synopsis><tag class="xmlpi">dbtimestamp format="<replaceable>formatstring</replaceable>" [padding="0"|"1"]</tag></synopsis>
  93. </refsynopsisdiv>
  94. <refparameter>
  95. <variablelist>
  96. <varlistentry><term>format="<replaceable>formatstring</replaceable>"</term>
  97. <listitem>
  98. <para>Specifies format in which the date and time are
  99. output</para>
  100. <note>
  101. <para>For details of the content of the format string,
  102. see <link role="tcg" xlink:href="Datetime.html"
  103. >Date and time</link>.</para>
  104. </note>
  105. </listitem>
  106. </varlistentry>
  107. <varlistentry><term>padding="0"|"1"</term>
  108. <listitem>
  109. <para>Specifies padding behavior; if non-zero, padding is is added</para>
  110. </listitem>
  111. </varlistentry>
  112. </variablelist>
  113. </refparameter>
  114. </doc:pi>
  115. <xsl:template name="pi.dbtimestamp">
  116. <xsl:variable name="format">
  117. <xsl:variable name="pi-format">
  118. <xsl:call-template name="pi-attribute">
  119. <xsl:with-param name="pis" select="."/>
  120. <xsl:with-param name="attribute">format</xsl:with-param>
  121. </xsl:call-template>
  122. </xsl:variable>
  123. <xsl:choose>
  124. <xsl:when test="$pi-format != ''">
  125. <xsl:value-of select="$pi-format"/>
  126. </xsl:when>
  127. <xsl:otherwise>
  128. <xsl:call-template name="gentext.template">
  129. <xsl:with-param name="context" select="'datetime'"/>
  130. <xsl:with-param name="name" select="'format'"/>
  131. </xsl:call-template>
  132. </xsl:otherwise>
  133. </xsl:choose>
  134. </xsl:variable>
  135. <xsl:variable name="padding">
  136. <xsl:variable name="pi-padding">
  137. <xsl:call-template name="pi-attribute">
  138. <xsl:with-param name="pis" select="."/>
  139. <xsl:with-param name="attribute">padding</xsl:with-param>
  140. </xsl:call-template>
  141. </xsl:variable>
  142. <xsl:choose>
  143. <xsl:when test="$pi-padding != ''">
  144. <xsl:value-of select="$pi-padding"/>
  145. </xsl:when>
  146. <xsl:otherwise>1</xsl:otherwise>
  147. </xsl:choose>
  148. </xsl:variable>
  149. <xsl:variable name="date">
  150. <xsl:choose>
  151. <xsl:when test="function-available('date:date-time')">
  152. <xsl:value-of select="date:date-time()"/>
  153. </xsl:when>
  154. <xsl:when test="function-available('date:dateTime')">
  155. <!-- Xalan quirk -->
  156. <xsl:value-of select="date:dateTime()"/>
  157. </xsl:when>
  158. </xsl:choose>
  159. </xsl:variable>
  160. <xsl:choose>
  161. <xsl:when test="function-available('date:date-time') or
  162. function-available('date:dateTime')">
  163. <xsl:call-template name="datetime.format">
  164. <xsl:with-param name="date" select="$date"/>
  165. <xsl:with-param name="format" select="$format"/>
  166. <xsl:with-param name="padding" select="$padding"/>
  167. </xsl:call-template>
  168. </xsl:when>
  169. <xsl:otherwise>
  170. <xsl:message>
  171. Timestamp processing requires XSLT processor with EXSLT date support.
  172. </xsl:message>
  173. </xsl:otherwise>
  174. </xsl:choose>
  175. </xsl:template>
  176. <doc:pi name="dbtex_delims" xmlns="">
  177. <refpurpose>Generates delimiters around embedded TeX equations
  178. in output</refpurpose>
  179. <refdescription>
  180. <para>Use the <tag class="xmlpi">dbtex delims</tag> PI as a
  181. child of a <tag>textobject</tag> containing embedded TeX
  182. markup, to cause that markup to be surrounded by
  183. <literal>$</literal> delimiter characters in output.</para>
  184. </refdescription>
  185. <refsynopsisdiv>
  186. <synopsis><tag class="xmlpi">dbtex delims="no"|"yes"</tag></synopsis>
  187. </refsynopsisdiv>
  188. <refparameter>
  189. <variablelist>
  190. <varlistentry><term>dbtex delims="no"|"yes"</term>
  191. <listitem>
  192. <para>Specifies whether delimiters are output</para>
  193. </listitem>
  194. </varlistentry>
  195. </variablelist>
  196. </refparameter>
  197. <refsee role="params">
  198. <para><parameter>tex.math.delims</parameter></para>
  199. </refsee>
  200. <refsee role="tcg">
  201. <para><link role="tcg"
  202. xlink:href="TexMath.html"
  203. >DBTeXMath</link></para>
  204. </refsee>
  205. </doc:pi>
  206. <xsl:template name="pi.dbtex_delims">
  207. <xsl:param name="node" select="."/>
  208. <xsl:call-template name="pi-attribute">
  209. <xsl:with-param name="pis" select="$node/processing-instruction('dbtex')"/>
  210. <xsl:with-param name="attribute" select="'delims'"/>
  211. </xsl:call-template>
  212. </xsl:template>
  213. <!-- ==================================================================== -->
  214. <xsl:template match="processing-instruction()" mode="titlepage.mode">
  215. <!-- * Als process PIs on title pages -->
  216. <xsl:apply-templates select="."/>
  217. </xsl:template>
  218. <xsl:template match="processing-instruction('dbtimestamp')">
  219. <xsl:call-template name="pi.dbtimestamp"/>
  220. </xsl:template>
  221. <xsl:template name="datetime.format">
  222. <xsl:param name="date"/>
  223. <xsl:param name="format"/>
  224. <xsl:param name="padding" select="1"/>
  225. <xsl:if test="$format != ''">
  226. <!-- replace any whitespace in the format string with a non-breaking space -->
  227. <xsl:variable name="format-nbsp"
  228. select="translate($format,
  229. '&#x20;&#x9;&#xd;&#xa;',
  230. '&#xa0;&#xa0;&#xa0;&#xa0;')"/>
  231. <xsl:variable name="tokenized-format-string">
  232. <xsl:call-template name="str.tokenize.keep.delimiters">
  233. <xsl:with-param name="string" select="$format-nbsp"/>
  234. <xsl:with-param name="delimiters" select="'&#xa0;,./-()[]:'"/>
  235. </xsl:call-template>
  236. </xsl:variable>
  237. <xsl:choose>
  238. <!-- include extra test for Xalan quirk -->
  239. <xsl:when test="function-available('exsl:node-set') or
  240. contains(system-property('xsl:vendor'),'Apache Software Foundation')">
  241. <!-- We must preserve context node in order to get valid language -->
  242. <xsl:variable name="context" select="."/>
  243. <xsl:for-each select="exsl:node-set($tokenized-format-string)/node()">
  244. <xsl:variable name="token">
  245. <xsl:value-of select="."/>
  246. </xsl:variable>
  247. <!-- Restore context node -->
  248. <xsl:for-each select="$context">
  249. <xsl:choose>
  250. <xsl:when test="$token = 'a'">
  251. <xsl:call-template name="gentext.template">
  252. <xsl:with-param name="context" select="'datetime-abbrev'"/>
  253. <xsl:with-param name="name" select="date:day-abbreviation($date)"/>
  254. </xsl:call-template>
  255. </xsl:when>
  256. <xsl:when test="$token = 'A'">
  257. <xsl:call-template name="gentext.template">
  258. <xsl:with-param name="context" select="'datetime-full'"/>
  259. <xsl:with-param name="name" select="date:day-name($date)"/>
  260. </xsl:call-template>
  261. </xsl:when>
  262. <xsl:when test="$token = 'b'">
  263. <xsl:call-template name="gentext.template">
  264. <xsl:with-param name="context" select="'datetime-abbrev'"/>
  265. <xsl:with-param name="name" select="date:month-abbreviation($date)"/>
  266. </xsl:call-template>
  267. </xsl:when>
  268. <xsl:when test="$token = 'c'">
  269. <xsl:value-of select="date:date($date)"/>
  270. <xsl:text> </xsl:text>
  271. <xsl:value-of select="date:time($date)"/>
  272. </xsl:when>
  273. <xsl:when test="$token = 'B'">
  274. <xsl:call-template name="gentext.template">
  275. <xsl:with-param name="context" select="'datetime-full'"/>
  276. <xsl:with-param name="name" select="date:month-name($date)"/>
  277. </xsl:call-template>
  278. </xsl:when>
  279. <xsl:when test="$token = 'd'">
  280. <xsl:if test="$padding = 1 and
  281. string-length(date:day-in-month($date)) = 1">0</xsl:if>
  282. <xsl:value-of select="date:day-in-month($date)"/>
  283. </xsl:when>
  284. <xsl:when test="$token = 'H'">
  285. <xsl:if test="$padding = 1 and string-length(date:hour-in-day($date)) = 1">0</xsl:if>
  286. <xsl:value-of select="date:hour-in-day($date)"/>
  287. </xsl:when>
  288. <xsl:when test="$token = 'j'">
  289. <xsl:value-of select="date:day-in-year($date)"/>
  290. </xsl:when>
  291. <xsl:when test="$token = 'm'">
  292. <xsl:if test="$padding = 1 and string-length(date:month-in-year($date)) = 1">0</xsl:if>
  293. <xsl:value-of select="date:month-in-year($date)"/>
  294. </xsl:when>
  295. <xsl:when test="$token = 'M'">
  296. <xsl:if test="string-length(date:minute-in-hour($date)) = 1">0</xsl:if>
  297. <xsl:value-of select="date:minute-in-hour($date)"/>
  298. </xsl:when>
  299. <xsl:when test="$token = 'S'">
  300. <xsl:if test="string-length(date:second-in-minute($date)) = 1">0</xsl:if>
  301. <xsl:value-of select="date:second-in-minute($date)"/>
  302. </xsl:when>
  303. <xsl:when test="$token = 'U'">
  304. <xsl:value-of select="date:week-in-year($date)"/>
  305. </xsl:when>
  306. <xsl:when test="$token = 'w'">
  307. <xsl:value-of select="date:day-in-week($date)"/>
  308. </xsl:when>
  309. <xsl:when test="$token = 'x'">
  310. <xsl:value-of select="date:date($date)"/>
  311. </xsl:when>
  312. <xsl:when test="$token = 'X'">
  313. <xsl:value-of select="date:time($date)"/>
  314. </xsl:when>
  315. <xsl:when test="$token = 'Y'">
  316. <xsl:value-of select="date:year($date)"/>
  317. </xsl:when>
  318. <xsl:otherwise>
  319. <xsl:value-of select="$token"/>
  320. </xsl:otherwise>
  321. </xsl:choose>
  322. </xsl:for-each>
  323. </xsl:for-each>
  324. </xsl:when>
  325. <xsl:otherwise>
  326. <xsl:message>
  327. Timestamp processing requires an XSLT processor with support
  328. for the EXSLT node-set() function.
  329. </xsl:message>
  330. </xsl:otherwise>
  331. </xsl:choose>
  332. </xsl:if>
  333. </xsl:template>
  334. </xsl:stylesheet>