pi.xsl 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
  4. xmlns:date="http://exslt.org/dates-and-times"
  5. xmlns:exsl="http://exslt.org/common"
  6. exclude-result-prefixes="doc date exsl"
  7. extension-element-prefixes="date exsl"
  8. version='1.0'>
  9. <!-- ********************************************************************
  10. $Id$
  11. ********************************************************************
  12. This file is part of the XSL DocBook Stylesheet distribution.
  13. See ../README or http://docbook.sf.net/release/xsl/current/ for
  14. copyright and other information.
  15. This file contains general templates for processing processing
  16. instructions common to both the HTML and FO versions of the
  17. DocBook stylesheets.
  18. ******************************************************************** -->
  19. <!-- Process PIs also on title pages -->
  20. <xsl:template match="processing-instruction()" mode="titlepage.mode">
  21. <xsl:apply-templates select="."/>
  22. </xsl:template>
  23. <xsl:template match="processing-instruction('dbtimestamp')">
  24. <xsl:variable name="format">
  25. <xsl:variable name="pi-format">
  26. <xsl:call-template name="pi-attribute">
  27. <xsl:with-param name="pis" select="."/>
  28. <xsl:with-param name="attribute">format</xsl:with-param>
  29. </xsl:call-template>
  30. </xsl:variable>
  31. <xsl:choose>
  32. <xsl:when test="$pi-format != ''">
  33. <xsl:value-of select="$pi-format"/>
  34. </xsl:when>
  35. <xsl:otherwise>
  36. <xsl:call-template name="gentext.template">
  37. <xsl:with-param name="context" select="'datetime'"/>
  38. <xsl:with-param name="name" select="'format'"/>
  39. </xsl:call-template>
  40. </xsl:otherwise>
  41. </xsl:choose>
  42. </xsl:variable>
  43. <xsl:variable name="padding">
  44. <xsl:variable name="pi-padding">
  45. <xsl:call-template name="pi-attribute">
  46. <xsl:with-param name="pis" select="."/>
  47. <xsl:with-param name="attribute">padding</xsl:with-param>
  48. </xsl:call-template>
  49. </xsl:variable>
  50. <xsl:choose>
  51. <xsl:when test="$pi-padding != ''">
  52. <xsl:value-of select="$pi-padding"/>
  53. </xsl:when>
  54. <xsl:otherwise>1</xsl:otherwise>
  55. </xsl:choose>
  56. </xsl:variable>
  57. <xsl:variable name="date">
  58. <xsl:choose>
  59. <xsl:when test="function-available('date:date-time')">
  60. <xsl:value-of select="date:date-time()"/>
  61. </xsl:when>
  62. <xsl:when test="function-available('date:dateTime')">
  63. <!-- Xalan quirk -->
  64. <xsl:value-of select="date:dateTime()"/>
  65. </xsl:when>
  66. </xsl:choose>
  67. </xsl:variable>
  68. <xsl:choose>
  69. <xsl:when test="function-available('date:date-time') or
  70. function-available('date:dateTime')">
  71. <xsl:call-template name="datetime.format">
  72. <xsl:with-param name="date" select="$date"/>
  73. <xsl:with-param name="format" select="$format"/>
  74. <xsl:with-param name="padding" select="$padding"/>
  75. </xsl:call-template>
  76. </xsl:when>
  77. <xsl:otherwise>
  78. <xsl:message>
  79. Timestamp processing requires XSLT processor with EXSLT date support.
  80. </xsl:message>
  81. </xsl:otherwise>
  82. </xsl:choose>
  83. </xsl:template>
  84. <xsl:template name="datetime.format">
  85. <xsl:param name="date"/>
  86. <xsl:param name="format"/>
  87. <xsl:param name="padding" select="1"/>
  88. <xsl:if test="$format != ''">
  89. <!-- replace any whitespace in the format string with a non-breaking space -->
  90. <xsl:variable name="format-nbsp"
  91. select="translate($format,
  92. '&#x20;&#x9;&#xd;&#xa;',
  93. '&#xa0;&#xa0;&#xa0;&#xa0;')"/>
  94. <xsl:variable name="tokenized-format-string">
  95. <xsl:call-template name="str.tokenize.keep.delimiters">
  96. <xsl:with-param name="string" select="$format-nbsp"/>
  97. <xsl:with-param name="delimiters" select="'&#xa0;,./-()[]:'"/>
  98. </xsl:call-template>
  99. </xsl:variable>
  100. <xsl:choose>
  101. <!-- include extra test for Xalan quirk -->
  102. <xsl:when test="function-available('exsl:node-set') or
  103. contains(system-property('xsl:vendor'),'Apache Software Foundation')">
  104. <!-- We must preserve context node in order to get valid language -->
  105. <xsl:variable name="context" select="."/>
  106. <xsl:for-each select="exsl:node-set($tokenized-format-string)/node()">
  107. <xsl:variable name="token">
  108. <xsl:value-of select="."/>
  109. </xsl:variable>
  110. <!-- Restore context node -->
  111. <xsl:for-each select="$context">
  112. <xsl:choose>
  113. <xsl:when test="$token = 'a'">
  114. <xsl:call-template name="gentext.template">
  115. <xsl:with-param name="context" select="'datetime-abbrev'"/>
  116. <xsl:with-param name="name" select="date:day-abbreviation($date)"/>
  117. </xsl:call-template>
  118. </xsl:when>
  119. <xsl:when test="$token = 'A'">
  120. <xsl:call-template name="gentext.template">
  121. <xsl:with-param name="context" select="'datetime-full'"/>
  122. <xsl:with-param name="name" select="date:day-name($date)"/>
  123. </xsl:call-template>
  124. </xsl:when>
  125. <xsl:when test="$token = 'b'">
  126. <xsl:call-template name="gentext.template">
  127. <xsl:with-param name="context" select="'datetime-abbrev'"/>
  128. <xsl:with-param name="name" select="date:month-abbreviation($date)"/>
  129. </xsl:call-template>
  130. </xsl:when>
  131. <xsl:when test="$token = 'c'">
  132. <xsl:value-of select="date:date($date)"/>
  133. <xsl:text> </xsl:text>
  134. <xsl:value-of select="date:time($date)"/>
  135. </xsl:when>
  136. <xsl:when test="$token = 'B'">
  137. <xsl:call-template name="gentext.template">
  138. <xsl:with-param name="context" select="'datetime-full'"/>
  139. <xsl:with-param name="name" select="date:month-name($date)"/>
  140. </xsl:call-template>
  141. </xsl:when>
  142. <xsl:when test="$token = 'd'">
  143. <xsl:if test="$padding = 1 and
  144. string-length(date:day-in-month($date)) = 1">0</xsl:if>
  145. <xsl:value-of select="date:day-in-month($date)"/>
  146. </xsl:when>
  147. <xsl:when test="$token = 'H'">
  148. <xsl:if test="$padding = 1 and string-length(date:hour-in-day($date)) = 1">0</xsl:if>
  149. <xsl:value-of select="date:hour-in-day($date)"/>
  150. </xsl:when>
  151. <xsl:when test="$token = 'j'">
  152. <xsl:value-of select="date:day-in-year($date)"/>
  153. </xsl:when>
  154. <xsl:when test="$token = 'm'">
  155. <xsl:if test="$padding = 1 and string-length(date:month-in-year($date)) = 1">0</xsl:if>
  156. <xsl:value-of select="date:month-in-year($date)"/>
  157. </xsl:when>
  158. <xsl:when test="$token = 'M'">
  159. <xsl:if test="string-length(date:minute-in-hour($date)) = 1">0</xsl:if>
  160. <xsl:value-of select="date:minute-in-hour($date)"/>
  161. </xsl:when>
  162. <xsl:when test="$token = 'S'">
  163. <xsl:if test="string-length(date:second-in-minute($date)) = 1">0</xsl:if>
  164. <xsl:value-of select="date:second-in-minute($date)"/>
  165. </xsl:when>
  166. <xsl:when test="$token = 'U'">
  167. <xsl:value-of select="date:week-in-year($date)"/>
  168. </xsl:when>
  169. <xsl:when test="$token = 'w'">
  170. <xsl:value-of select="date:day-in-week($date)"/>
  171. </xsl:when>
  172. <xsl:when test="$token = 'x'">
  173. <xsl:value-of select="date:date($date)"/>
  174. </xsl:when>
  175. <xsl:when test="$token = 'X'">
  176. <xsl:value-of select="date:time($date)"/>
  177. </xsl:when>
  178. <xsl:when test="$token = 'Y'">
  179. <xsl:value-of select="date:year($date)"/>
  180. </xsl:when>
  181. <xsl:otherwise>
  182. <xsl:value-of select="$token"/>
  183. </xsl:otherwise>
  184. </xsl:choose>
  185. </xsl:for-each>
  186. </xsl:for-each>
  187. </xsl:when>
  188. <xsl:otherwise>
  189. <xsl:message>
  190. Timestamp processing requires an XSLT processor with support
  191. for the EXSLT node-set() function.
  192. </xsl:message>
  193. </xsl:otherwise>
  194. </xsl:choose>
  195. </xsl:if>
  196. </xsl:template>
  197. </xsl:stylesheet>