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

Extracting hours, minutes, and seconds from time

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="time"
                              select="current-time()"/>
                  <time>
                        <xsl:value-of  select="$time"/>
                  </time>
                  <hours>
                        <xsl:value-of  select="hours-from-time($time)"/>
                  </hours>
                  <minutes>
                        <xsl:value-of  select="minutes-from-time($time)"/>
                  </minutes>
                  <seconds>
                        <xsl:value-of  select="seconds-from-time($time)"/>
                  </seconds>
                  <timezone>
                        <xsl:value-of  select="timezone-from-time($time)"/>
                  </timezone>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa/>
Output

      <time>14:13:30.716+01:00</time>
      <hours>14</hours>
      <minutes>13</minutes>
      <seconds>30.716</seconds>
      <timezone>PT1H</timezone>


Previous chapter: Recursions
Next chapter: Comments and processing instructions
Previous page: Extracting day, month, and year from date
Next page: Extracting all data from dateTime