title: XSLT: date calculation inside of a function [format-dateTime() ]
body: <p>I would like to do date calculation inside of format-dateTime() function and do XSL transformation. Here is my XSL file</p>
  
  <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns="http://www.abc.com/ws/integration/toolkit/2005/07" xmlns:fct="http://www.taleo.com/xsl_functions" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;xsl:output method="xml" encoding="UTF-8"/&gt;
  &lt;xsl:template match="/"&gt;
      &lt;xsl:apply-templates/&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="@*|node()"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:apply-templates select="@*|node()"/&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match="ns:field[@name = 'EndDate']"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:apply-templates select="@*"/&gt;
          &lt;xsl:value-of select="fct:format-considering-timezone(xs:dateTime(.))"/&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:function name="fct:format-considering-timezone"&gt;
      &lt;xsl:param name="dateTime" as="xs:dateTime"/&gt;
      &lt;xsl:variable name="dst"&gt;
          &lt;xsl:value-of select="fct:get-timezone($dateTime)"/&gt;
      &lt;/xsl:variable&gt;
      &lt;xsl:variable name="date-format"&gt;
          &lt;xsl:choose&gt;
              &lt;xsl:when test="$dst = 'PT11H'"&gt;[Y,4-4]-[M,2-2]-[D,2-2]02:00:00T-05:00&lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;[Y,4-4]-[M,2-2]-[D,2-2]00:00:00T-05:00&lt;/xsl:otherwise&gt;
          &lt;/xsl:choose&gt;
      &lt;/xsl:variable&gt;               
      &lt;xsl:variable name="Duration"&gt;
          &lt;xsl:choose&gt;
              &lt;xsl:when test="ns:field[@name='CareerSiteNo3'] = 'xyz'"&gt;P2D&lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;P14D&lt;/xsl:otherwise&gt;
          &lt;/xsl:choose&gt;
      &lt;/xsl:variable&gt;
      &lt;xsl:variable name="AUTime"&gt;
          &lt;xsl:value-of select="adjust-dateTime-to-timezone($dateTime + xs:dayTimeDuration($Duration), $dst)"/&gt;
      &lt;/xsl:variable&gt;
      &lt;xsl:value-of select="format-dateTime((xs:datetime($AUTime) + xs:dayTimeDuration($Duration)), $date-format)"/&gt;
  &lt;/xsl:function&gt;
  &lt;xsl:function name="fct:get-timezone" as="xs:dayTimeDuration"&gt;
      &lt;xsl:param name="dateTime" as="xs:dateTime"/&gt;
      &lt;xsl:variable name="timezone"&gt;
          &lt;xsl:choose&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2030-10-06T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2030-04-07T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2029-10-07T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2029-04-01T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2028-10-01T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2028-04-02T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2027-10-03T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2027-04-04T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2026-10-04T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2026-04-05T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2025-10-05T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2025-04-06T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2024-10-06T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2024-04-07T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2023-10-01T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2023-04-02T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2022-10-02T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2022-04-03T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2021-10-03T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2021-04-04T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2020-10-04T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2020-04-05T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2019-10-06T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2019-04-07T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2018-10-07T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2018-04-01T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2017-10-01T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2017-04-02T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2016-10-02T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2016-04-03T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2015-10-04T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2015-04-05T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2014-10-05T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2014-04-06T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2013-10-06T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2013-04-07T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2012-10-07T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2012-04-01T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2011-10-02T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2011-04-03T03:00:00+10:00')"&gt;PT10H&lt;/xsl:when&gt;
              &lt;xsl:when test="$dateTime gt xs:dateTime('2010-10-03T02:00:00+11:00')"&gt;PT11H&lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;
                  &lt;xsl:value-of select="concat(' Error - dateTime : ', $dateTime, ' out of range. Need to extend the list of DST datetimes.')"/&gt;
              &lt;/xsl:otherwise&gt;
          &lt;/xsl:choose&gt;
      &lt;/xsl:variable&gt;
      &lt;xsl:value-of select="xs:dayTimeDuration($timezone)"/&gt;
  &lt;/xsl:function&gt;
  </code></pre>
  
  <p></p>
  
  <p>This code causes an error
  "TransformerConfigurationException: Failed to compile stylesheet. 1 error detected.".</p>
  
  <p>Here is the output I am wanting to transform:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;Body&gt;
      &lt;getDocumentByKeyResponse xmlns="http://www.abc.com/ws/integration/toolkit/2005/07" xmlns:ns1="http://www.abc.com/ws/integration/toolkit/2005/07" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;
          &lt;Document&gt;
              &lt;Attributes&gt;
                  &lt;Attribute name="duration"&gt;0:00:00.086&lt;/Attribute&gt;
                  &lt;Attribute name="count"&gt;2&lt;/Attribute&gt;
                  &lt;Attribute name="entity"&gt;SourcingRequest&lt;/Attribute&gt;
                  &lt;Attribute name="mode"&gt;XML&lt;/Attribute&gt;
                  &lt;Attribute name="version"&gt;http://www.taleo.com/ws/tee800/2009/01&lt;/Attribute&gt;
              &lt;/Attributes&gt;
              &lt;Content&gt;
                  &lt;ExportXML&gt;
                      &lt;record&gt;
                          &lt;field name="Identifier"&gt;00000abc&lt;/field&gt;
                          &lt;field name="ContestNumber"&gt;00000abc&lt;/field&gt;
                          &lt;field name="CareerSiteNo3"&gt;xyz&lt;/field&gt;
                          &lt;field name="OpeningDate"&gt;2012-02-15&lt;/field&gt;
                          &lt;field name="EndDate"&gt;2012-02-1602:00:00T-05:00&lt;/field&gt;
                      &lt;/record&gt;
              &lt;/Content&gt;
          &lt;/Document&gt;
      &lt;/getDocumentByKeyResponse&gt;
  &lt;/Body&gt;
  </code></pre>
  
  <p></p>
  
  <p>When I changed the part
  <code>&lt;xsl:value-of select="format-dateTime((xs:datetime($AUTime) + xs:dayTimeDuration($Duration)), $date-format)"/&gt;</code>like this <code>&lt;xsl:value-of select="format-dateTime($AUTime, $date-format)"/&gt;</code>, which does not contain data calculation, the transformation process succeeds.</p>
  
  <p>Is it NOT possible to do a calculation inside <code>format-dateTime()&gt;</code>?</p>
  
  <p>Many thanks </p>