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: pi.xsl 8782 2010-07-27 21:15:17Z mzjn $
  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: pi.xsl 8782 2010-07-27 21:15:17Z mzjn $
  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. <warning>
  185. <para>This feature is useful for print/PDF output only if you
  186. use the obsolete and now unsupported PassiveTeX XSL-FO
  187. engine.</para>
  188. </warning>
  189. </refdescription>
  190. <refsynopsisdiv>
  191. <synopsis><tag class="xmlpi">dbtex delims="no"|"yes"</tag></synopsis>
  192. </refsynopsisdiv>
  193. <refparameter>
  194. <variablelist>
  195. <varlistentry><term>dbtex delims="no"|"yes"</term>
  196. <listitem>
  197. <para>Specifies whether delimiters are output</para>
  198. </listitem>
  199. </varlistentry>
  200. </variablelist>
  201. </refparameter>
  202. <refsee role="params">
  203. <para><parameter>tex.math.delims</parameter></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. <xsl:when test="$exsl.node.set.available != 0">
  239. <!-- We must preserve context node in order to get valid language -->
  240. <xsl:variable name="context" select="."/>
  241. <xsl:for-each select="exsl:node-set($tokenized-format-string)/node()">
  242. <xsl:variable name="token">
  243. <xsl:value-of select="."/>
  244. </xsl:variable>
  245. <!-- Restore context node -->
  246. <xsl:for-each select="$context">
  247. <xsl:choose>
  248. <xsl:when test="$token = 'a'">
  249. <xsl:call-template name="gentext.template">
  250. <xsl:with-param name="context" select="'datetime-abbrev'"/>
  251. <xsl:with-param name="name" select="date:day-abbreviation($date)"/>
  252. </xsl:call-template>
  253. </xsl:when>
  254. <xsl:when test="$token = 'A'">
  255. <xsl:call-template name="gentext.template">
  256. <xsl:with-param name="context" select="'datetime-full'"/>
  257. <xsl:with-param name="name" select="date:day-name($date)"/>
  258. </xsl:call-template>
  259. </xsl:when>
  260. <xsl:when test="$token = 'b'">
  261. <xsl:call-template name="gentext.template">
  262. <xsl:with-param name="context" select="'datetime-abbrev'"/>
  263. <xsl:with-param name="name" select="date:month-abbreviation($date)"/>
  264. </xsl:call-template>
  265. </xsl:when>
  266. <xsl:when test="$token = 'c'">
  267. <xsl:value-of select="date:date($date)"/>
  268. <xsl:text> </xsl:text>
  269. <xsl:value-of select="date:time($date)"/>
  270. </xsl:when>
  271. <xsl:when test="$token = 'B'">
  272. <xsl:call-template name="gentext.template">
  273. <xsl:with-param name="context" select="'datetime-full'"/>
  274. <xsl:with-param name="name" select="date:month-name($date)"/>
  275. </xsl:call-template>
  276. </xsl:when>
  277. <xsl:when test="$token = 'd'">
  278. <xsl:if test="$padding = 1 and
  279. string-length(date:day-in-month($date)) = 1">0</xsl:if>
  280. <xsl:value-of select="date:day-in-month($date)"/>
  281. </xsl:when>
  282. <xsl:when test="$token = 'H'">
  283. <xsl:if test="$padding = 1 and string-length(date:hour-in-day($date)) = 1">0</xsl:if>
  284. <xsl:value-of select="date:hour-in-day($date)"/>
  285. </xsl:when>
  286. <xsl:when test="$token = 'j'">
  287. <xsl:value-of select="date:day-in-year($date)"/>
  288. </xsl:when>
  289. <xsl:when test="$token = 'm'">
  290. <xsl:if test="$padding = 1 and string-length(date:month-in-year($date)) = 1">0</xsl:if>
  291. <xsl:value-of select="date:month-in-year($date)"/>
  292. </xsl:when>
  293. <xsl:when test="$token = 'M'">
  294. <xsl:if test="string-length(date:minute-in-hour($date)) = 1">0</xsl:if>
  295. <xsl:value-of select="date:minute-in-hour($date)"/>
  296. </xsl:when>
  297. <xsl:when test="$token = 'S'">
  298. <xsl:if test="string-length(date:second-in-minute($date)) = 1">0</xsl:if>
  299. <xsl:value-of select="date:second-in-minute($date)"/>
  300. </xsl:when>
  301. <xsl:when test="$token = 'U'">
  302. <xsl:value-of select="date:week-in-year($date)"/>
  303. </xsl:when>
  304. <xsl:when test="$token = 'w'">
  305. <xsl:value-of select="date:day-in-week($date)"/>
  306. </xsl:when>
  307. <xsl:when test="$token = 'x'">
  308. <xsl:value-of select="date:date($date)"/>
  309. </xsl:when>
  310. <xsl:when test="$token = 'X'">
  311. <xsl:value-of select="date:time($date)"/>
  312. </xsl:when>
  313. <xsl:when test="$token = 'Y'">
  314. <xsl:value-of select="date:year($date)"/>
  315. </xsl:when>
  316. <xsl:otherwise>
  317. <xsl:value-of select="$token"/>
  318. </xsl:otherwise>
  319. </xsl:choose>
  320. </xsl:for-each>
  321. </xsl:for-each>
  322. </xsl:when>
  323. <xsl:otherwise>
  324. <xsl:message>
  325. Timestamp processing requires an XSLT processor with support
  326. for the EXSLT node-set() function.
  327. </xsl:message>
  328. </xsl:otherwise>
  329. </xsl:choose>
  330. </xsl:if>
  331. </xsl:template>
  332. </xsl:stylesheet>