Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

date-time.xsl 45KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0"
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
  5. xmlns:dt="http://xsltsl.org/date-time"
  6. xmlns:str="http://xsltsl.org/string"
  7. extension-element-prefixes="doc str">
  8. <doc:reference xmlns="">
  9. <referenceinfo>
  10. <releaseinfo role="meta">
  11. $Id: date-time.xsl,v 1.11 2004/10/10 06:18:57 balls Exp $
  12. </releaseinfo>
  13. <author>
  14. <surname>Diamond</surname>
  15. <firstname>Jason</firstname>
  16. </author>
  17. <copyright>
  18. <year>2004</year>
  19. <holder>Steve Ball</holder>
  20. </copyright>
  21. <copyright>
  22. <year>2001</year>
  23. <holder>Jason Diamond</holder>
  24. </copyright>
  25. </referenceinfo>
  26. <title>Date/Time Processing</title>
  27. <partintro>
  28. <section>
  29. <title>Introduction</title>
  30. <para>This module provides templates for formatting and parsing date/time strings.</para>
  31. <para>See <ulink url="http://www.tondering.dk/claus/calendar.html">http://www.tondering.dk/claus/calendar.html</ulink> for more information on calendars and the calculations this library performs.</para>
  32. </section>
  33. </partintro>
  34. </doc:reference>
  35. <doc:template name="dt:format-date-time" xmlns="">
  36. <refpurpose>Returns a string with a formatted date/time.</refpurpose>
  37. <refdescription>
  38. <para>The formatted date/time is determined by the format parameter. The default format is %Y-%m-%dT%H:%M:%S%z, the W3C format.</para>
  39. </refdescription>
  40. <refparameter>
  41. <variablelist>
  42. <varlistentry>
  43. <term>xsd-date-time</term>
  44. <listitem>
  45. <para>The date-time value in XML Schemas (WXS) format.</para>
  46. <para>If this value is specified, it takes priority over other parameters.</para>
  47. </listitem>
  48. </varlistentry>
  49. <varlistentry>
  50. <term>year</term>
  51. <listitem>
  52. <para>Year</para>
  53. </listitem>
  54. </varlistentry>
  55. <varlistentry>
  56. <term>month</term>
  57. <listitem>
  58. <para>Month (1 - 12; January = 1)</para>
  59. </listitem>
  60. </varlistentry>
  61. <varlistentry>
  62. <term>day</term>
  63. <listitem>
  64. <para>Day of month (1 - 31)</para>
  65. </listitem>
  66. </varlistentry>
  67. <varlistentry>
  68. <term>hour</term>
  69. <listitem>
  70. <para>Hours since midnight (0 - 23)</para>
  71. </listitem>
  72. </varlistentry>
  73. <varlistentry>
  74. <term>minute</term>
  75. <listitem>
  76. <para>Minutes after hour (0 - 59)</para>
  77. </listitem>
  78. </varlistentry>
  79. <varlistentry>
  80. <term>second</term>
  81. <listitem>
  82. <para>Seconds after minute (0 - 59)</para>
  83. </listitem>
  84. </varlistentry>
  85. <varlistentry>
  86. <term>time-zone</term>
  87. <listitem>
  88. <para>Time zone string (e.g., 'Z' or '-08:00')</para>
  89. </listitem>
  90. </varlistentry>
  91. <varlistentry>
  92. <term>format</term>
  93. <listitem>
  94. <para>The format specification.</para>
  95. <variablelist>
  96. <varlistentry>
  97. <term>%a</term>
  98. <listitem>
  99. <para>Abbreviated weekday name</para>
  100. </listitem>
  101. </varlistentry>
  102. <varlistentry>
  103. <term>%A</term>
  104. <listitem>
  105. <para>Full weekday name</para>
  106. </listitem>
  107. </varlistentry>
  108. <varlistentry>
  109. <term>%b</term>
  110. <listitem>
  111. <para>Abbreviated month name</para>
  112. </listitem>
  113. </varlistentry>
  114. <varlistentry>
  115. <term>%B</term>
  116. <listitem>
  117. <para>Full month name</para>
  118. </listitem>
  119. </varlistentry>
  120. <varlistentry>
  121. <term>%c</term>
  122. <listitem>
  123. <para>Date and time representation appropriate for locale</para>
  124. </listitem>
  125. </varlistentry>
  126. <varlistentry>
  127. <term>%d</term>
  128. <listitem>
  129. <para>Day of month as decimal number (01 - 31)</para>
  130. </listitem>
  131. </varlistentry>
  132. <varlistentry>
  133. <term>%e</term>
  134. <listitem>
  135. <para>Day of month as decimal number (1 - 31)</para>
  136. </listitem>
  137. </varlistentry>
  138. <varlistentry>
  139. <term>%H</term>
  140. <listitem>
  141. <para>Hour in 24-hour format (00 - 23)</para>
  142. </listitem>
  143. </varlistentry>
  144. <varlistentry>
  145. <term>%I</term>
  146. <listitem>
  147. <para>Hour in 12-hour format (01 - 12)</para>
  148. </listitem>
  149. </varlistentry>
  150. <varlistentry>
  151. <term>%i</term>
  152. <listitem>
  153. <para>Hour in 12-hour format (1 - 12)</para>
  154. </listitem>
  155. </varlistentry>
  156. <varlistentry>
  157. <term>%j</term>
  158. <listitem>
  159. <para>Day of year as decimal number (001 - 366)</para>
  160. </listitem>
  161. </varlistentry>
  162. <varlistentry>
  163. <term>%m</term>
  164. <listitem>
  165. <para>Month as decimal number (01 - 12)</para>
  166. </listitem>
  167. </varlistentry>
  168. <varlistentry>
  169. <term>%n</term>
  170. <listitem>
  171. <para>Month as decimal number (1 - 12)</para>
  172. </listitem>
  173. </varlistentry>
  174. <varlistentry>
  175. <term>%M</term>
  176. <listitem>
  177. <para>Minute as decimal number (00 - 59)</para>
  178. </listitem>
  179. </varlistentry>
  180. <varlistentry>
  181. <term>%P</term>
  182. <listitem>
  183. <para>Current locale's A.M./P.M. indicator for 12-hour clock, uppercase</para>
  184. </listitem>
  185. </varlistentry>
  186. <varlistentry>
  187. <term>%Q</term>
  188. <listitem>
  189. <para>Current locale's A.M./P.M. indicator for 12-hour clock, uppercase with periods</para>
  190. </listitem>
  191. </varlistentry>
  192. <varlistentry>
  193. <term>%p</term>
  194. <listitem>
  195. <para>Current locale's A.M./P.M. indicator for 12-hour clock, lowercase</para>
  196. </listitem>
  197. </varlistentry>
  198. <varlistentry>
  199. <term>%q</term>
  200. <listitem>
  201. <para>Current locale's A.M./P.M. indicator for 12-hour clock, lowercase with periods</para>
  202. </listitem>
  203. </varlistentry>
  204. <varlistentry>
  205. <term>%S</term>
  206. <listitem>
  207. <para>Second as decimal number (00 - 59)</para>
  208. </listitem>
  209. </varlistentry>
  210. <varlistentry>
  211. <term>%U</term>
  212. <listitem>
  213. <para>Week of year as decimal number, with Sunday as first day of week (00 - 53)</para>
  214. </listitem>
  215. </varlistentry>
  216. <varlistentry>
  217. <term>%w</term>
  218. <listitem>
  219. <para>Weekday as decimal number (0 - 6; Sunday is 0)</para>
  220. </listitem>
  221. </varlistentry>
  222. <varlistentry>
  223. <term>%W</term>
  224. <listitem>
  225. <para>Week of year as decimal number, with Monday as first day of week (00 - 53)</para>
  226. </listitem>
  227. </varlistentry>
  228. <varlistentry>
  229. <term>%x</term>
  230. <listitem>
  231. <para>Date representation for current locale </para>
  232. </listitem>
  233. </varlistentry>
  234. <varlistentry>
  235. <term>%X</term>
  236. <listitem>
  237. <para>Time representation for current locale</para>
  238. </listitem>
  239. </varlistentry>
  240. <varlistentry>
  241. <term>%y</term>
  242. <listitem>
  243. <para>Year without century, as decimal number (00 - 99)</para>
  244. </listitem>
  245. </varlistentry>
  246. <varlistentry>
  247. <term>%Y</term>
  248. <listitem>
  249. <para>Year with century, as decimal number</para>
  250. </listitem>
  251. </varlistentry>
  252. <varlistentry>
  253. <term>%z</term>
  254. <listitem>
  255. <para>Time-zone name or abbreviation; no characters if time zone is unknown</para>
  256. </listitem>
  257. </varlistentry>
  258. <varlistentry>
  259. <term>%%</term>
  260. <listitem>
  261. <para>Percent sign</para>
  262. </listitem>
  263. </varlistentry>
  264. </variablelist>
  265. </listitem>
  266. </varlistentry>
  267. </variablelist>
  268. </refparameter>
  269. <refreturn>
  270. <para>Returns a formatted date/time string.</para>
  271. </refreturn>
  272. </doc:template>
  273. <xsl:template name="dt:format-date-time">
  274. <xsl:param name='xsd-date-time'/>
  275. <xsl:param name="year"/>
  276. <xsl:param name="month"/>
  277. <xsl:param name="day"/>
  278. <xsl:param name="hour"/>
  279. <xsl:param name="minute"/>
  280. <xsl:param name="second"/>
  281. <xsl:param name="time-zone"/>
  282. <xsl:param name="format" select="'%Y-%m-%dT%H:%M:%S%z'"/>
  283. <xsl:value-of select="substring-before($format, '%')"/>
  284. <xsl:variable name="code" select="substring(substring-after($format, '%'), 1, 1)"/>
  285. <xsl:choose>
  286. <xsl:when test='$xsd-date-time'>
  287. <xsl:call-template name='dt:format-date-time'>
  288. <xsl:with-param name='year'>
  289. <xsl:call-template name='dt:get-xsd-datetime-year'>
  290. <xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
  291. </xsl:call-template>
  292. </xsl:with-param>
  293. <xsl:with-param name='month'>
  294. <xsl:call-template name='dt:get-xsd-datetime-month'>
  295. <xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
  296. </xsl:call-template>
  297. </xsl:with-param>
  298. <xsl:with-param name='day'>
  299. <xsl:call-template name='dt:get-xsd-datetime-day'>
  300. <xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
  301. </xsl:call-template>
  302. </xsl:with-param>
  303. <xsl:with-param name='hour'>
  304. <xsl:call-template name='dt:get-xsd-datetime-hour'>
  305. <xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
  306. </xsl:call-template>
  307. </xsl:with-param>
  308. <xsl:with-param name='minute'>
  309. <xsl:call-template name='dt:get-xsd-datetime-minute'>
  310. <xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
  311. </xsl:call-template>
  312. </xsl:with-param>
  313. <xsl:with-param name='second'>
  314. <xsl:call-template name='dt:get-xsd-datetime-second'>
  315. <xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
  316. </xsl:call-template>
  317. </xsl:with-param>
  318. <xsl:with-param name='time-zone'>
  319. <xsl:call-template name='dt:get-xsd-datetime-timezone'>
  320. <xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
  321. </xsl:call-template>
  322. </xsl:with-param>
  323. <xsl:with-param name='format'>
  324. <xsl:choose>
  325. <xsl:when test='contains($format, "%")'>
  326. <xsl:text>%</xsl:text>
  327. <xsl:value-of select='substring-after($format, "%")'/>
  328. </xsl:when>
  329. <xsl:otherwise>
  330. <xsl:value-of select='$format'/>
  331. </xsl:otherwise>
  332. </xsl:choose>
  333. </xsl:with-param>
  334. </xsl:call-template>
  335. </xsl:when>
  336. <!-- Abbreviated weekday name -->
  337. <xsl:when test="$code='a'">
  338. <xsl:variable name="day-of-the-week">
  339. <xsl:call-template name="dt:calculate-day-of-the-week">
  340. <xsl:with-param name="year" select="$year"/>
  341. <xsl:with-param name="month" select="$month"/>
  342. <xsl:with-param name="day" select="$day"/>
  343. </xsl:call-template>
  344. </xsl:variable>
  345. <xsl:call-template name="dt:get-day-of-the-week-abbreviation">
  346. <xsl:with-param name="day-of-the-week" select="$day-of-the-week"/>
  347. </xsl:call-template>
  348. </xsl:when>
  349. <!-- Full weekday name -->
  350. <xsl:when test="$code='A'">
  351. <xsl:variable name="day-of-the-week">
  352. <xsl:call-template name="dt:calculate-day-of-the-week">
  353. <xsl:with-param name="year" select="$year"/>
  354. <xsl:with-param name="month" select="$month"/>
  355. <xsl:with-param name="day" select="$day"/>
  356. </xsl:call-template>
  357. </xsl:variable>
  358. <xsl:call-template name="dt:get-day-of-the-week-name">
  359. <xsl:with-param name="day-of-the-week" select="$day-of-the-week"/>
  360. </xsl:call-template>
  361. </xsl:when>
  362. <!-- Abbreviated month name -->
  363. <xsl:when test="$code='b'">
  364. <xsl:call-template name="dt:get-month-abbreviation">
  365. <xsl:with-param name="month" select="$month"/>
  366. </xsl:call-template>
  367. </xsl:when>
  368. <!-- Full month name -->
  369. <xsl:when test="$code='B'">
  370. <xsl:call-template name="dt:get-month-name">
  371. <xsl:with-param name="month" select="$month"/>
  372. </xsl:call-template>
  373. </xsl:when>
  374. <!-- Date and time representation appropriate for locale -->
  375. <xsl:when test="$code='c'">
  376. <xsl:text>[not implemented]</xsl:text>
  377. </xsl:when>
  378. <!-- Day of month as decimal number (01 - 31) -->
  379. <xsl:when test="$code='d'">
  380. <xsl:if test="$day &lt; 10">0</xsl:if>
  381. <xsl:value-of select="number($day)"/>
  382. </xsl:when>
  383. <!-- Day of month as decimal number (1 - 31) -->
  384. <xsl:when test="$code='e'">
  385. <xsl:value-of select="number($day)"/>
  386. </xsl:when>
  387. <!-- Hour in 24-hour format (00 - 23) -->
  388. <xsl:when test="$code='H'">
  389. <xsl:if test="$hour &lt; 10">0</xsl:if>
  390. <xsl:value-of select="number($hour)"/>
  391. </xsl:when>
  392. <!-- Hour in 12-hour format (01 - 12) -->
  393. <xsl:when test="$code='I'">
  394. <xsl:choose>
  395. <xsl:when test="$hour = 0">12</xsl:when>
  396. <xsl:when test="$hour &lt; 10">0<xsl:value-of select="$hour - 0"/></xsl:when>
  397. <xsl:when test="$hour &lt; 13"><xsl:value-of select="$hour - 0"/></xsl:when>
  398. <xsl:when test="$hour &lt; 22">0<xsl:value-of select="$hour - 12"/></xsl:when>
  399. <xsl:otherwise><xsl:value-of select="$hour - 12"/></xsl:otherwise>
  400. </xsl:choose>
  401. </xsl:when>
  402. <!-- Hour in 12-hour format (1 - 12) -->
  403. <xsl:when test="$code='i'">
  404. <xsl:choose>
  405. <xsl:when test="$hour = 0">12</xsl:when>
  406. <xsl:when test="$hour &lt; 10"><xsl:value-of select="$hour - 0"/></xsl:when>
  407. <xsl:when test="$hour &lt; 13"><xsl:value-of select="$hour - 0"/></xsl:when>
  408. <xsl:when test="$hour &lt; 22"><xsl:value-of select="$hour - 12"/></xsl:when>
  409. <xsl:otherwise><xsl:value-of select="$hour - 12"/></xsl:otherwise>
  410. </xsl:choose>
  411. </xsl:when>
  412. <!-- Day of year as decimal number (001 - 366) -->
  413. <xsl:when test="$code='j'">
  414. <xsl:text>[not implemented]</xsl:text>
  415. </xsl:when>
  416. <!-- Month as decimal number (01 - 12) -->
  417. <xsl:when test="$code='m'">
  418. <xsl:if test="$month &lt; 10">0</xsl:if>
  419. <xsl:value-of select="number($month)"/>
  420. </xsl:when>
  421. <!-- Month as decimal number (1 - 12) -->
  422. <xsl:when test="$code='n'">
  423. <xsl:value-of select="number($month)"/>
  424. </xsl:when>
  425. <!-- Minute as decimal number (00 - 59) -->
  426. <xsl:when test="$code='M'">
  427. <xsl:if test="$minute &lt; 10">0</xsl:if>
  428. <xsl:value-of select="number($minute)"/>
  429. </xsl:when>
  430. <!-- Current locale's A.M./P.M. indicator for 12-hour clock -->
  431. <xsl:when test="$code='p'">
  432. <xsl:choose>
  433. <xsl:when test="$hour &lt; 12">am</xsl:when>
  434. <xsl:otherwise>pm</xsl:otherwise>
  435. </xsl:choose>
  436. </xsl:when>
  437. <!-- Current locale's A.M./P.M. indicator for 12-hour clock with periods -->
  438. <xsl:when test="$code='q'">
  439. <xsl:choose>
  440. <xsl:when test="$hour &lt; 12">am</xsl:when>
  441. <xsl:otherwise>p.m.</xsl:otherwise>
  442. </xsl:choose>
  443. </xsl:when>
  444. <!-- Current locale's A.M./P.M. indicator for 12-hour clock -->
  445. <xsl:when test="$code='P'">
  446. <xsl:choose>
  447. <xsl:when test="$hour &lt; 12">AM</xsl:when>
  448. <xsl:otherwise>PM</xsl:otherwise>
  449. </xsl:choose>
  450. </xsl:when>
  451. <!-- Current locale's A.M./P.M. indicator for 12-hour clock with periods -->
  452. <xsl:when test="$code='Q'">
  453. <xsl:choose>
  454. <xsl:when test="$hour &lt; 12">AM</xsl:when>
  455. <xsl:otherwise>P.M.</xsl:otherwise>
  456. </xsl:choose>
  457. </xsl:when>
  458. <!-- Second as decimal number (00 - 59) -->
  459. <xsl:when test="$code='S'">
  460. <xsl:if test="$second &lt; 10">0</xsl:if>
  461. <xsl:value-of select="number($second)"/>
  462. </xsl:when>
  463. <!-- Week of year as decimal number, with Sunday as first day of week (00 - 53) -->
  464. <xsl:when test="$code='U'">
  465. <!-- add 1 to day -->
  466. <xsl:call-template name="dt:calculate-week-number">
  467. <xsl:with-param name="year" select="$year"/>
  468. <xsl:with-param name="month" select="$month"/>
  469. <xsl:with-param name="day" select="$day + 1"/>
  470. </xsl:call-template>
  471. </xsl:when>
  472. <!-- Weekday as decimal number (0 - 6; Sunday is 0) -->
  473. <xsl:when test="$code='w'">
  474. <xsl:call-template name="dt:calculate-day-of-the-week">
  475. <xsl:with-param name="year" select="$year"/>
  476. <xsl:with-param name="month" select="$month"/>
  477. <xsl:with-param name="day" select="$day"/>
  478. </xsl:call-template>
  479. </xsl:when>
  480. <!-- Week of year as decimal number, with Monday as first day of week (00 - 53) -->
  481. <xsl:when test="$code='W'">
  482. <xsl:call-template name="dt:calculate-week-number">
  483. <xsl:with-param name="year" select="$year"/>
  484. <xsl:with-param name="month" select="$month"/>
  485. <xsl:with-param name="day" select="$day"/>
  486. </xsl:call-template>
  487. </xsl:when>
  488. <!-- Date representation for current locale -->
  489. <xsl:when test="$code='x'">
  490. <xsl:text>[not implemented]</xsl:text>
  491. </xsl:when>
  492. <!-- Time representation for current locale -->
  493. <xsl:when test="$code='X'">
  494. <xsl:text>[not implemented]</xsl:text>
  495. </xsl:when>
  496. <!-- Year without century, as decimal number (00 - 99) -->
  497. <xsl:when test="$code='y'">
  498. <xsl:text>[not implemented]</xsl:text>
  499. </xsl:when>
  500. <!-- Year with century, as decimal number -->
  501. <xsl:when test="$code='Y'">
  502. <xsl:value-of select="concat(substring('000', string-length(number($year))), $year)"/>
  503. </xsl:when>
  504. <!-- Time-zone name or abbreviation; no characters if time zone is unknown -->
  505. <xsl:when test="$code='z'">
  506. <xsl:value-of select="$time-zone"/>
  507. </xsl:when>
  508. <!-- Percent sign -->
  509. <xsl:when test="$code='%'">
  510. <xsl:text>%</xsl:text>
  511. </xsl:when>
  512. </xsl:choose>
  513. <xsl:variable name="remainder" select="substring(substring-after($format, '%'), 2)"/>
  514. <xsl:if test="not($xsd-date-time) and $remainder">
  515. <xsl:call-template name="dt:format-date-time">
  516. <xsl:with-param name="year" select="$year"/>
  517. <xsl:with-param name="month" select="$month"/>
  518. <xsl:with-param name="day" select="$day"/>
  519. <xsl:with-param name="hour" select="$hour"/>
  520. <xsl:with-param name="minute" select="$minute"/>
  521. <xsl:with-param name="second" select="$second"/>
  522. <xsl:with-param name="time-zone" select="$time-zone"/>
  523. <xsl:with-param name="format" select="$remainder"/>
  524. </xsl:call-template>
  525. </xsl:if>
  526. </xsl:template>
  527. <doc:template name="dt:calculate-day-of-the-week" xmlns="">
  528. <refpurpose>Calculates the day of the week.</refpurpose>
  529. <refdescription>
  530. <para>Given any Gregorian date, this calculates the day of the week.</para>
  531. </refdescription>
  532. <refparameter>
  533. <variablelist>
  534. <varlistentry>
  535. <term>year</term>
  536. <listitem>
  537. <para>Year</para>
  538. </listitem>
  539. </varlistentry>
  540. <varlistentry>
  541. <term>month</term>
  542. <listitem>
  543. <para>Month (1 - 12; January = 1)</para>
  544. </listitem>
  545. </varlistentry>
  546. <varlistentry>
  547. <term>day</term>
  548. <listitem>
  549. <para>Day of month (1 - 31)</para>
  550. </listitem>
  551. </varlistentry>
  552. </variablelist>
  553. </refparameter>
  554. <refreturn>
  555. <para>Returns the day of the week (0 - 6; Sunday = 0).</para>
  556. </refreturn>
  557. </doc:template>
  558. <xsl:template name="dt:calculate-day-of-the-week">
  559. <xsl:param name="year"/>
  560. <xsl:param name="month"/>
  561. <xsl:param name="day"/>
  562. <xsl:variable name="a" select="floor((14 - $month) div 12)"/>
  563. <xsl:variable name="y" select="$year - $a"/>
  564. <xsl:variable name="m" select="$month + 12 * $a - 2"/>
  565. <xsl:value-of select="($day + $y + floor($y div 4) - floor($y div 100) + floor($y div 400) + floor((31 * $m) div 12)) mod 7"/>
  566. </xsl:template>
  567. <doc:template name="dt:calculate-last-day-of-month" xmlns="">
  568. <refpurpose>Calculates the number of days for a specified month.</refpurpose>
  569. <refdescription>
  570. <para>Given any Gregorian month, this calculates the last day of the month.</para>
  571. </refdescription>
  572. <refparameter>
  573. <variablelist>
  574. <varlistentry>
  575. <term>year</term>
  576. <listitem>
  577. <para>Year</para>
  578. </listitem>
  579. </varlistentry>
  580. <varlistentry>
  581. <term>month</term>
  582. <listitem>
  583. <para>Month (1 - 12; January = 1)</para>
  584. </listitem>
  585. </varlistentry>
  586. </variablelist>
  587. </refparameter>
  588. <refreturn>
  589. <para>Returns the number of days in given month as a decimal number.</para>
  590. </refreturn>
  591. </doc:template>
  592. <xsl:template name="dt:calculate-last-day-of-month">
  593. <xsl:param name="year"/>
  594. <xsl:param name="month"/>
  595. <xsl:choose>
  596. <xsl:when test="$month = 2">
  597. <xsl:choose>
  598. <xsl:when test="($year mod 4) = 0 and (($year mod 400) = 0
  599. or ($year mod 100) != 0)">29</xsl:when>
  600. <xsl:otherwise>28</xsl:otherwise>
  601. </xsl:choose>
  602. </xsl:when>
  603. <xsl:when test="$month &lt; 8">
  604. <xsl:choose>
  605. <xsl:when test="$month mod 2 = 0">30</xsl:when>
  606. <xsl:otherwise>31</xsl:otherwise>
  607. </xsl:choose>
  608. </xsl:when>
  609. <xsl:otherwise>
  610. <xsl:choose>
  611. <xsl:when test="$month mod 2 = 1">30</xsl:when>
  612. <xsl:otherwise>31</xsl:otherwise>
  613. </xsl:choose>
  614. </xsl:otherwise>
  615. </xsl:choose>
  616. </xsl:template>
  617. <doc:template name="dt:get-day-of-the-week-name" xmlns="">
  618. <refpurpose>Gets the day of the week's full name.</refpurpose>
  619. <refdescription>
  620. <para>Converts a numeric day of the week value into a string representing the day's full name.</para>
  621. </refdescription>
  622. <refparameter>
  623. <variablelist>
  624. <varlistentry>
  625. <term>day-of-the-week</term>
  626. <listitem>
  627. <para>Day of the week (0 - 6; Sunday = 0)</para>
  628. </listitem>
  629. </varlistentry>
  630. </variablelist>
  631. </refparameter>
  632. <refreturn>
  633. <para>Returns a string.</para>
  634. </refreturn>
  635. </doc:template>
  636. <xsl:template name="dt:get-day-of-the-week-name">
  637. <xsl:param name="day-of-the-week"/>
  638. <xsl:choose>
  639. <xsl:when test="$day-of-the-week = 0">Sunday</xsl:when>
  640. <xsl:when test="$day-of-the-week = 1">Monday</xsl:when>
  641. <xsl:when test="$day-of-the-week = 2">Tuesday</xsl:when>
  642. <xsl:when test="$day-of-the-week = 3">Wednesday</xsl:when>
  643. <xsl:when test="$day-of-the-week = 4">Thursday</xsl:when>
  644. <xsl:when test="$day-of-the-week = 5">Friday</xsl:when>
  645. <xsl:when test="$day-of-the-week = 6">Saturday</xsl:when>
  646. <xsl:otherwise>error: <xsl:value-of select="$day-of-the-week"/></xsl:otherwise>
  647. </xsl:choose>
  648. </xsl:template>
  649. <doc:template name="dt:get-day-of-the-week-abbreviation" xmlns="">
  650. <refpurpose>Gets the day of the week's abbreviation.</refpurpose>
  651. <refdescription>
  652. <para>Converts a numeric day of the week value into a string representing the day's abbreviation.</para>
  653. </refdescription>
  654. <refparameter>
  655. <variablelist>
  656. <varlistentry>
  657. <term>day-of-the-week</term>
  658. <listitem>
  659. <para>Day of the week (0 - 6; Sunday = 0)</para>
  660. </listitem>
  661. </varlistentry>
  662. </variablelist>
  663. </refparameter>
  664. <refreturn>
  665. <para>Returns a string.</para>
  666. </refreturn>
  667. </doc:template>
  668. <xsl:template name="dt:get-day-of-the-week-abbreviation">
  669. <xsl:param name="day-of-the-week"/>
  670. <xsl:choose>
  671. <xsl:when test="$day-of-the-week = 0">Sun</xsl:when>
  672. <xsl:when test="$day-of-the-week = 1">Mon</xsl:when>
  673. <xsl:when test="$day-of-the-week = 2">Tue</xsl:when>
  674. <xsl:when test="$day-of-the-week = 3">Wed</xsl:when>
  675. <xsl:when test="$day-of-the-week = 4">Thu</xsl:when>
  676. <xsl:when test="$day-of-the-week = 5">Fri</xsl:when>
  677. <xsl:when test="$day-of-the-week = 6">Sat</xsl:when>
  678. <xsl:otherwise>error: <xsl:value-of select="$day-of-the-week"/></xsl:otherwise>
  679. </xsl:choose>
  680. </xsl:template>
  681. <doc:template name="dt:get-month-name" xmlns="">
  682. <refpurpose>Gets the month's full name.</refpurpose>
  683. <refdescription>
  684. <para>Converts a numeric month value into a string representing the month's full name.</para>
  685. </refdescription>
  686. <refparameter>
  687. <variablelist>
  688. <varlistentry>
  689. <term>month</term>
  690. <listitem>
  691. <para>Month (1 - 12; Januaray = 1)</para>
  692. </listitem>
  693. </varlistentry>
  694. </variablelist>
  695. </refparameter>
  696. <refreturn>
  697. <para>Returns a string.</para>
  698. </refreturn>
  699. </doc:template>
  700. <xsl:template name="dt:get-month-name">
  701. <xsl:param name="month"/>
  702. <xsl:choose>
  703. <xsl:when test="$month = 1">January</xsl:when>
  704. <xsl:when test="$month = 2">February</xsl:when>
  705. <xsl:when test="$month = 3">March</xsl:when>
  706. <xsl:when test="$month = 4">April</xsl:when>
  707. <xsl:when test="$month = 5">May</xsl:when>
  708. <xsl:when test="$month = 6">June</xsl:when>
  709. <xsl:when test="$month = 7">July</xsl:when>
  710. <xsl:when test="$month = 8">August</xsl:when>
  711. <xsl:when test="$month = 9">September</xsl:when>
  712. <xsl:when test="$month = 10">October</xsl:when>
  713. <xsl:when test="$month = 11">November</xsl:when>
  714. <xsl:when test="$month = 12">December</xsl:when>
  715. <xsl:otherwise>error: <xsl:value-of select="$month"/></xsl:otherwise>
  716. </xsl:choose>
  717. </xsl:template>
  718. <doc:template name="dt:get-month-abbreviation" xmlns="">
  719. <refpurpose>Gets the month's abbreviation.</refpurpose>
  720. <refdescription>
  721. <para>Converts a numeric month value into a string representing the month's abbreviation.</para>
  722. </refdescription>
  723. <refparameter>
  724. <variablelist>
  725. <varlistentry>
  726. <term>month</term>
  727. <listitem>
  728. <para>Month (1 - 12; Januaray = 1)</para>
  729. </listitem>
  730. </varlistentry>
  731. </variablelist>
  732. </refparameter>
  733. <refreturn>
  734. <para>Returns a string.</para>
  735. </refreturn>
  736. </doc:template>
  737. <xsl:template name="dt:get-month-abbreviation">
  738. <xsl:param name="month"/>
  739. <xsl:choose>
  740. <xsl:when test="$month = 1">Jan</xsl:when>
  741. <xsl:when test="$month = 2">Feb</xsl:when>
  742. <xsl:when test="$month = 3">Mar</xsl:when>
  743. <xsl:when test="$month = 4">Apr</xsl:when>
  744. <xsl:when test="$month = 5">May</xsl:when>
  745. <xsl:when test="$month = 6">Jun</xsl:when>
  746. <xsl:when test="$month = 7">Jul</xsl:when>
  747. <xsl:when test="$month = 8">Aug</xsl:when>
  748. <xsl:when test="$month = 9">Sep</xsl:when>
  749. <xsl:when test="$month = 10">Oct</xsl:when>
  750. <xsl:when test="$month = 11">Nov</xsl:when>
  751. <xsl:when test="$month = 12">Dec</xsl:when>
  752. <xsl:otherwise>error: <xsl:value-of select="$month"/></xsl:otherwise>
  753. </xsl:choose>
  754. </xsl:template>
  755. <doc:template name="dt:calculate-julian-day" xmlns="">
  756. <refpurpose>Calculates the Julian Day for a specified date.</refpurpose>
  757. <refdescription>
  758. <para>Given any Gregorian date, this calculates the Julian Day.</para>
  759. </refdescription>
  760. <refparameter>
  761. <variablelist>
  762. <varlistentry>
  763. <term>year</term>
  764. <listitem>
  765. <para>Year</para>
  766. </listitem>
  767. </varlistentry>
  768. <varlistentry>
  769. <term>month</term>
  770. <listitem>
  771. <para>Month (1 - 12; January = 1)</para>
  772. </listitem>
  773. </varlistentry>
  774. <varlistentry>
  775. <term>day</term>
  776. <listitem>
  777. <para>Day of month (1 - 31)</para>
  778. </listitem>
  779. </varlistentry>
  780. </variablelist>
  781. </refparameter>
  782. <refreturn>
  783. <para>Returns the Julian Day as a decimal number.</para>
  784. </refreturn>
  785. </doc:template>
  786. <xsl:template name="dt:calculate-julian-day">
  787. <xsl:param name="year"/>
  788. <xsl:param name="month"/>
  789. <xsl:param name="day"/>
  790. <xsl:variable name="a" select="floor((14 - $month) div 12)"/>
  791. <xsl:variable name="y" select="$year + 4800 - $a"/>
  792. <xsl:variable name="m" select="$month + 12 * $a - 3"/>
  793. <xsl:value-of select="$day + floor((153 * $m + 2) div 5) + $y * 365 + floor($y div 4) - floor($y div 100) + floor($y div 400) - 32045"/>
  794. </xsl:template>
  795. <doc:template name="dt:format-julian-day" xmlns="">
  796. <refpurpose>Returns a string with a formatted date for a specified Julian Day.</refpurpose>
  797. <refdescription>
  798. <para>Given any Julian Day, this returns a string according to the format specification.</para>
  799. </refdescription>
  800. <refparameter>
  801. <variablelist>
  802. <varlistentry>
  803. <term>julian-day</term>
  804. <listitem>
  805. <para>A Julian Day</para>
  806. </listitem>
  807. </varlistentry>
  808. <varlistentry>
  809. <term>format</term>
  810. <listitem>
  811. <para>The format specification. See dt:format-date-time for more details.</para>
  812. </listitem>
  813. </varlistentry>
  814. </variablelist>
  815. </refparameter>
  816. <refreturn>
  817. <para>A string.</para>
  818. </refreturn>
  819. </doc:template>
  820. <xsl:template name="dt:format-julian-day">
  821. <xsl:param name="julian-day"/>
  822. <xsl:param name="format" select="'%Y-%m-%d'"/>
  823. <xsl:variable name="a" select="$julian-day + 32044"/>
  824. <xsl:variable name="b" select="floor((4 * $a + 3) div 146097)"/>
  825. <xsl:variable name="c" select="$a - floor(($b * 146097) div 4)"/>
  826. <xsl:variable name="d" select="floor((4 * $c + 3) div 1461)"/>
  827. <xsl:variable name="e" select="$c - floor((1461 * $d) div 4)"/>
  828. <xsl:variable name="m" select="floor((5 * $e + 2) div 153)"/>
  829. <xsl:variable name="day" select="$e - floor((153 * $m + 2) div 5) + 1"/>
  830. <xsl:variable name="month" select="$m + 3 - 12 * floor($m div 10)"/>
  831. <xsl:variable name="year" select="$b * 100 + $d - 4800 + floor($m div 10)"/>
  832. <xsl:call-template name="dt:format-date-time">
  833. <xsl:with-param name="year" select="$year"/>
  834. <xsl:with-param name="month" select="$month"/>
  835. <xsl:with-param name="day" select="$day"/>
  836. <xsl:with-param name="format" select="$format"/>
  837. </xsl:call-template>
  838. </xsl:template>
  839. <doc:template name="dt:calculate-week-number" xmlns="">
  840. <refpurpose>Calculates the week number for a specified date.</refpurpose>
  841. <refdescription>
  842. <para>Assumes Monday is the first day of the week.</para>
  843. </refdescription>
  844. <refparameter>
  845. <variablelist>
  846. <varlistentry>
  847. <term>year</term>
  848. <listitem>
  849. <para>Year</para>
  850. </listitem>
  851. </varlistentry>
  852. <varlistentry>
  853. <term>month</term>
  854. <listitem>
  855. <para>Month (1 - 12; January = 1)</para>
  856. </listitem>
  857. </varlistentry>
  858. <varlistentry>
  859. <term>day</term>
  860. <listitem>
  861. <para>Day of month (1 - 31)</para>
  862. </listitem>
  863. </varlistentry>
  864. </variablelist>
  865. </refparameter>
  866. <refreturn>
  867. <para>Returns the week number as a decimal number.</para>
  868. </refreturn>
  869. </doc:template>
  870. <xsl:template name="dt:calculate-week-number">
  871. <xsl:param name="year"/>
  872. <xsl:param name="month"/>
  873. <xsl:param name="day"/>
  874. <xsl:variable name="J">
  875. <xsl:call-template name="dt:calculate-julian-day">
  876. <xsl:with-param name="year" select="$year"/>
  877. <xsl:with-param name="month" select="$month"/>
  878. <xsl:with-param name="day" select="$day"/>
  879. </xsl:call-template>
  880. </xsl:variable>
  881. <xsl:variable name="d4" select="($J + 31741 - ($J mod 7)) mod 146097 mod 36524 mod 1461"/>
  882. <xsl:variable name="L" select="floor($d4 div 1460)"/>
  883. <xsl:variable name="d1" select="(($d4 - $L) mod 365) + $L"/>
  884. <xsl:value-of select="floor($d1 div 7) + 1"/>
  885. </xsl:template>
  886. <doc:template name="dt:get-month-number" xmlns="">
  887. <refpurpose>Take a month by name and return a number which can be used as input to the templates. </refpurpose>
  888. <refdescription>
  889. <para>Input</para>
  890. </refdescription>
  891. <refparameter>
  892. <variablelist>
  893. <varlistentry>
  894. <term>month</term>
  895. <listitem>
  896. <para>Month as described either by full name or abbreviation.</para>
  897. </listitem>
  898. </varlistentry>
  899. </variablelist>
  900. </refparameter>
  901. <refreturn>
  902. <para>Return a month as a decimal number. (Jan = 1)</para>
  903. </refreturn>
  904. </doc:template>
  905. <xsl:template name='dt:get-month-number'>
  906. <xsl:param name='month'/>
  907. <xsl:variable name='monToUpper'>
  908. <xsl:call-template name='str:to-upper'>
  909. <xsl:with-param name='text' select='$month'/>
  910. </xsl:call-template>
  911. </xsl:variable>
  912. <xsl:choose>
  913. <xsl:when test='starts-with($monToUpper,"JAN")'>
  914. <xsl:value-of select='"1"'/>
  915. </xsl:when>
  916. <xsl:when test='starts-with($monToUpper,"FEB")'>
  917. <xsl:value-of select='2'/>
  918. </xsl:when>
  919. <xsl:when test='starts-with($monToUpper,"MAR")'>
  920. <xsl:value-of select='3'/>
  921. </xsl:when>
  922. <xsl:when test='starts-with($monToUpper,"APR")'>
  923. <xsl:value-of select='4'/>
  924. </xsl:when>
  925. <xsl:when test='starts-with($monToUpper,"MAY")'>
  926. <xsl:value-of select='5'/>
  927. </xsl:when>
  928. <xsl:when test='starts-with($monToUpper,"JUN")'>
  929. <xsl:value-of select='6'/>
  930. </xsl:when>
  931. <xsl:when test='starts-with($monToUpper,"JUL")'>
  932. <xsl:value-of select='7'/>
  933. </xsl:when>
  934. <xsl:when test='starts-with($monToUpper,"AUG")'>
  935. <xsl:value-of select='8'/>
  936. </xsl:when>
  937. <xsl:when test='starts-with($monToUpper,"SEP")'>
  938. <xsl:value-of select='9'/>
  939. </xsl:when>
  940. <xsl:when test='starts-with($monToUpper,"OCT")'>
  941. <xsl:value-of select='10'/>
  942. </xsl:when>
  943. <xsl:when test='starts-with($monToUpper,"NOV")'>
  944. <xsl:value-of select='11'/>
  945. </xsl:when>
  946. <xsl:when test='starts-with($monToUpper,"DEC")'>
  947. <xsl:value-of select='"12"'/>
  948. </xsl:when>
  949. </xsl:choose>
  950. </xsl:template>
  951. <doc:template name="dt:get-xsd-datetime-year" xmlns="">
  952. <refpurpose>Return year component of XSD DateTime value.</refpurpose>
  953. <refdescription>
  954. <para>Extract component of XML Schemas DateTime value.</para>
  955. </refdescription>
  956. <refparameter>
  957. <variablelist>
  958. <varlistentry>
  959. <term>xsd-date-time</term>
  960. <listitem>
  961. <para>A value in XSD DateTime format.</para>
  962. </listitem>
  963. </varlistentry>
  964. </variablelist>
  965. </refparameter>
  966. <refreturn>
  967. <para>Returns year component.</para>
  968. </refreturn>
  969. </doc:template>
  970. <xsl:template name='dt:get-xsd-datetime-year'>
  971. <xsl:param name='xsd-date-time'/>
  972. <xsl:choose>
  973. <xsl:when test='contains($xsd-date-time, "T")'>
  974. <xsl:call-template name='dt:get-xsd-datetime-year'>
  975. <xsl:with-param name='xsd-date-time' select='substring-before($xsd-date-time, "T")'/>
  976. </xsl:call-template>
  977. </xsl:when>
  978. <!-- Check for time -->
  979. <xsl:when test='substring($xsd-date-time, 3, 1) = ":"'/>
  980. <xsl:otherwise>
  981. <!-- This is a date -->
  982. <xsl:value-of select='substring-before($xsd-date-time, "-")'/>
  983. </xsl:otherwise>
  984. </xsl:choose>
  985. </xsl:template>
  986. <doc:template name="dt:get-xsd-datetime-month" xmlns="">
  987. <refpurpose>Return month component of XSD DateTime value.</refpurpose>
  988. <refdescription>
  989. <para>Extract component of XML Schemas DateTime value.</para>
  990. </refdescription>
  991. <refparameter>
  992. <variablelist>
  993. <varlistentry>
  994. <term>xsd-date-time</term>
  995. <listitem>
  996. <para>A value in XSD DateTime format.</para>
  997. </listitem>
  998. </varlistentry>
  999. </variablelist>
  1000. </refparameter>
  1001. <refreturn>
  1002. <para>Returns month component.</para>
  1003. </refreturn>
  1004. </doc:template>
  1005. <xsl:template name='dt:get-xsd-datetime-month'>
  1006. <xsl:param name='xsd-date-time'/>
  1007. <xsl:choose>
  1008. <xsl:when test='contains($xsd-date-time, "T")'>
  1009. <xsl:call-template name='dt:get-xsd-datetime-month'>
  1010. <xsl:with-param name='xsd-date-time' select='substring-before($xsd-date-time, "T")'/>
  1011. </xsl:call-template>
  1012. </xsl:when>
  1013. <!-- Check for time -->
  1014. <xsl:when test='substring($xsd-date-time, 3, 1) = ":"'/>
  1015. <xsl:otherwise>
  1016. <!-- This is a date -->
  1017. <xsl:value-of select='substring(substring-after($xsd-date-time, "-"), 1, 2)'/>
  1018. </xsl:otherwise>
  1019. </xsl:choose>
  1020. </xsl:template>
  1021. <doc:template name="dt:get-xsd-datetime-day" xmlns="">
  1022. <refpurpose>Return day component of XSD DateTime value.</refpurpose>
  1023. <refdescription>
  1024. <para>Extract component of XML Schemas DateTime value.</para>
  1025. </refdescription>
  1026. <refparameter>
  1027. <variablelist>
  1028. <varlistentry>
  1029. <term>xsd-date-time</term>
  1030. <listitem>
  1031. <para>A value in XSD DateTime format.</para>
  1032. </listitem>
  1033. </varlistentry>
  1034. </variablelist>
  1035. </refparameter>
  1036. <refreturn>
  1037. <para>Returns day component.</para>
  1038. </refreturn>
  1039. </doc:template>
  1040. <xsl:template name='dt:get-xsd-datetime-day'>
  1041. <xsl:param name='xsd-date-time'/>
  1042. <xsl:choose>
  1043. <xsl:when test='contains($xsd-date-time, "T")'>
  1044. <xsl:call-template name='dt:get-xsd-datetime-day'>
  1045. <xsl:with-param name='xsd-date-time' select='substring-before($xsd-date-time, "T")'/>
  1046. </xsl:call-template>
  1047. </xsl:when>
  1048. <!-- Check for time -->
  1049. <xsl:when test='substring($xsd-date-time, 3, 1) = ":"'/>
  1050. <xsl:otherwise>
  1051. <!-- This is a date -->
  1052. <xsl:value-of select='substring(substring-after($xsd-date-time, "-"), 4, 2)'/>
  1053. </xsl:otherwise>
  1054. </xsl:choose>
  1055. </xsl:template>
  1056. <doc:template name="dt:get-xsd-datetime-hour" xmlns="">
  1057. <refpurpose>Return hour component of XSD DateTime value.</refpurpose>
  1058. <refdescription>
  1059. <para>Extract component of XML Schemas DateTime value.</para>
  1060. </refdescription>
  1061. <refparameter>
  1062. <variablelist>
  1063. <varlistentry>
  1064. <term>xsd-date-time</term>
  1065. <listitem>
  1066. <para>A value in XSD DateTime format.</para>
  1067. </listitem>
  1068. </varlistentry>
  1069. </variablelist>
  1070. </refparameter>
  1071. <refreturn>
  1072. <para>Returns hour component.</para>
  1073. </refreturn>
  1074. </doc:template>
  1075. <xsl:template name='dt:get-xsd-datetime-hour'>
  1076. <xsl:param name='xsd-date-time'/>
  1077. <xsl:choose>
  1078. <xsl:when test='contains($xsd-date-time, "T")'>
  1079. <xsl:call-template name='dt:get-xsd-datetime-hour'>
  1080. <xsl:with-param name='xsd-date-time' select='substring-after($xsd-date-time, "T")'/>
  1081. </xsl:call-template>
  1082. </xsl:when>
  1083. <!-- Check for time -->
  1084. <xsl:when test='substring($xsd-date-time, 3, 1) = ":"'>
  1085. <xsl:value-of select='substring($xsd-date-time, 1, 2)'/>
  1086. </xsl:when>
  1087. <xsl:otherwise>
  1088. <!-- This is a date -->
  1089. </xsl:otherwise>
  1090. </xsl:choose>
  1091. </xsl:template>
  1092. <doc:template name="dt:get-xsd-datetime-minute" xmlns="">
  1093. <refpurpose>Return minute component of XSD DateTime value.</refpurpose>
  1094. <refdescription>
  1095. <para>Extract component of XML Schemas DateTime value.</para>
  1096. </refdescription>
  1097. <refparameter>
  1098. <variablelist>
  1099. <varlistentry>
  1100. <term>xsd-date-time</term>
  1101. <listitem>
  1102. <para>A value in XSD DateTime format.</para>
  1103. </listitem>
  1104. </varlistentry>
  1105. </variablelist>
  1106. </refparameter>
  1107. <refreturn>
  1108. <para>Returns minute component.</para>
  1109. </refreturn>
  1110. </doc:template>
  1111. <xsl:template name='dt:get-xsd-datetime-minute'>
  1112. <xsl:param name='xsd-date-time'/>
  1113. <xsl:choose>
  1114. <xsl:when test='contains($xsd-date-time, "T")'>
  1115. <xsl:call-template name='dt:get-xsd-datetime-minute'>
  1116. <xsl:with-param name='xsd-date-time' select='substring-after($xsd-date-time, "T")'/>
  1117. </xsl:call-template>
  1118. </xsl:when>
  1119. <!-- Check for time -->
  1120. <xsl:when test='substring($xsd-date-time, 3, 1) = ":"'>
  1121. <xsl:value-of select='substring($xsd-date-time, 4, 2)'/>
  1122. </xsl:when>
  1123. <xsl:otherwise>
  1124. <!-- This is a date -->
  1125. </xsl:otherwise>
  1126. </xsl:choose>
  1127. </xsl:template>
  1128. <doc:template name="dt:get-xsd-datetime-second" xmlns="">
  1129. <refpurpose>Return second component of XSD DateTime value.</refpurpose>
  1130. <refdescription>
  1131. <para>Extract component of XML Schemas DateTime value.</para>
  1132. </refdescription>
  1133. <refparameter>
  1134. <variablelist>
  1135. <varlistentry>
  1136. <term>xsd-date-time</term>
  1137. <listitem>
  1138. <para>A value in XSD DateTime format.</para>
  1139. </listitem>
  1140. </varlistentry>
  1141. </variablelist>
  1142. </refparameter>
  1143. <refreturn>
  1144. <para>Returns second component.</para>
  1145. </refreturn>
  1146. </doc:template>
  1147. <xsl:template name='dt:get-xsd-datetime-second'>
  1148. <xsl:param name='xsd-date-time'/>
  1149. <xsl:choose>
  1150. <xsl:when test='contains($xsd-date-time, "T")'>
  1151. <xsl:call-template name='dt:get-xsd-datetime-second'>
  1152. <xsl:with-param name='xsd-date-time' select='substring-after($xsd-date-time, "T")'/>
  1153. </xsl:call-template>
  1154. </xsl:when>
  1155. <!-- Check for time -->
  1156. <xsl:when test='substring($xsd-date-time, 3, 1) = ":"'>
  1157. <xsl:variable name='part' select='substring($xsd-date-time, 7)'/>
  1158. <xsl:choose>
  1159. <xsl:when test='contains($part, "Z")'>
  1160. <xsl:value-of select='substring-before($part, "Z")'/>
  1161. </xsl:when>
  1162. <xsl:when test='contains($part, "+")'>
  1163. <xsl:value-of select='substring-before($part, "+")'/>
  1164. </xsl:when>
  1165. <xsl:when test='contains($part, "-")'>
  1166. <xsl:value-of select='substring-before($part, "-")'/>
  1167. </xsl:when>
  1168. <xsl:otherwise>
  1169. <xsl:value-of select='$part'/>
  1170. </xsl:otherwise>
  1171. </xsl:choose>
  1172. </xsl:when>
  1173. <xsl:otherwise>
  1174. <!-- This is a date -->
  1175. </xsl:otherwise>
  1176. </xsl:choose>
  1177. </xsl:template>
  1178. <doc:template name="dt:get-xsd-datetime-timezone" xmlns="">
  1179. <refpurpose>Return timezone component of XSD DateTime value.</refpurpose>
  1180. <refdescription>
  1181. <para>Extract component of XML Schemas DateTime value.</para>
  1182. </refdescription>
  1183. <refparameter>
  1184. <variablelist>
  1185. <varlistentry>
  1186. <term>xsd-date-time</term>
  1187. <listitem>
  1188. <para>A value in XSD DateTime format.</para>
  1189. </listitem>
  1190. </varlistentry>
  1191. </variablelist>
  1192. </refparameter>
  1193. <refreturn>
  1194. <para>Returns timezone component.</para>
  1195. </refreturn>
  1196. </doc:template>
  1197. <xsl:template name='dt:get-xsd-datetime-timezone'>
  1198. <xsl:param name='xsd-date-time'/>
  1199. <xsl:choose>
  1200. <xsl:when test='contains($xsd-date-time, "Z")'>Z</xsl:when>
  1201. <xsl:when test='contains($xsd-date-time, "T")'>
  1202. <xsl:call-template name='dt:get-xsd-datetime-timezone'>
  1203. <xsl:with-param name='xsd-date-time' select='substring-after($xsd-date-time, "T")'/>
  1204. </xsl:call-template>
  1205. </xsl:when>
  1206. <xsl:when test='substring($xsd-date-time, 3, 1) = ":"'>
  1207. <!-- This is a time -->
  1208. <xsl:choose>
  1209. <xsl:when test='contains($xsd-date-time, "+")'>
  1210. <xsl:text>+</xsl:text>
  1211. <xsl:value-of select='substring-after($xsd-date-time, "+")'/>
  1212. </xsl:when>
  1213. <xsl:when test='contains($xsd-date-time, "-")'>
  1214. <xsl:text>-</xsl:text>
  1215. <xsl:value-of select='substring-after($xsd-date-time, "-")'/>
  1216. </xsl:when>
  1217. </xsl:choose>
  1218. </xsl:when>
  1219. <xsl:otherwise>
  1220. <!-- This is a date -->
  1221. <xsl:value-of select='substring(substring-after($xsd-date-time, "-"), 6)'/>
  1222. </xsl:otherwise>
  1223. </xsl:choose>
  1224. </xsl:template>
  1225. </xsl:stylesheet>