Previous | Next | Indexes
Zvon > Tutorials > XSLT 2.0 Tutorial > Date and Time (4/7) >

Extracting all data from dateTime

XSLT

      <xsl:stylesheet
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0">
            <xsl:output  method="xml"
                        indent="yes"
                        omit-xml-declaration="yes"/>

            <xsl:template  match="/aaa">
                  <xsl:variable  name="dt"
                              select="current-dateTime()"/>
                  <time>
                        <xsl:value-of  select="$dt"/>
                  </time>
                  <day>
                        <xsl:value-of  select="day-from-dateTime($dt)"/>
                  </day>
                  <month>
                        <xsl:value-of  select="month-from-dateTime($dt)"/>
                  </month>
                  <year>
                        <xsl:value-of  select="year-from-dateTime($dt)"/>
                  </year>
                  <hours>
                        <xsl:value-of  select="hours-from-dateTime($dt)"/>
                  </hours>
                  <minutes>
                        <xsl:value-of  select="minutes-from-dateTime($dt)"/>
                  </minutes>
                  <seconds>
                        <xsl:value-of  select="seconds-from-dateTime($dt)"/>
                  </seconds>
                  <timezone>
                        <xsl:value-of  select="timezone-from-dateTime($dt)"/>
                  </timezone>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa/>
Output

      <time>2005-12-13T14:13:31.869+01:00</time>
      <day>13</day>
      <month>12</month>
      <year>2005</year>
      <hours>14</hours>
      <minutes>13</minutes>
      <seconds>31.869</seconds>
      <timezone>PT1H</timezone>


Previous chapter: Recursions
Next chapter: Comments and processing instructions
Previous page: Extracting hours, minutes, and seconds from time
Next page: Subtracting times