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

Subtracting dates

XSLT

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

            <xsl:template  match="/aaa">
                  <a>
                        <xsl:value-of  select="'2005-12-04' cast as sch:date - '1999-04-11' cast as sch:date"/>
                  </a>
                  <b>
                        <xsl:value-of  select="current-date() - '0001-01-01' cast as sch:date"/>
                  </b>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa/>
Output

      <a>P2429D</a>
      <b>P732292D</b>


Previous chapter: Recursions
Next chapter: Comments and processing instructions
Previous page: Subtracting times
Next page: Days, months, and years from durations