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

Extracting day, month, and year from date

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="date"
                              select="current-date()"/>
                  <date>
                        <xsl:value-of  select="$date"/>
                  </date>
                  <day>
                        <xsl:value-of  select="day-from-date($date)"/>
                  </day>
                  <month>
                        <xsl:value-of  select="month-from-date($date)"/>
                  </month>
                  <year>
                        <xsl:value-of  select="year-from-date($date)"/>
                  </year>
                  <timezone>
                        <xsl:value-of  select="timezone-from-date($date)"/>
                  </timezone>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa/>
Output

      <date>2005-12-13+01:00</date>
      <day>13</day>
      <month>12</month>
      <year>2005</year>
      <timezone>PT1H</timezone>


Previous chapter: Recursions
Next chapter: Comments and processing instructions
Previous page: Finding current date and time
Next page: Extracting hours, minutes, and seconds from time