title: XSLT: UTC TimeStamp convert into Time Zone using adjust-dateTime-to-timezone
body: <p>I'm trying to covert a UTC timestamp based on some time zone information in the XML into my target TZ dependent timestamp.</p>
  <p>Using the xslt funtion <code>adjust-dateTime-to-timezone($utc-timestamp, xs:dayTimeDuration('PT2H')</code> this is not a problem but the conversion must be dynamic based on the TZ information from the source file (mainly Java TZs).</p>
  <p>Just an example which is working but not really dynamic:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;xsl:stylesheet version=&quot;3.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;
      xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
      &lt;xsl:output method=&quot;xml&quot; version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; indent=&quot;yes&quot;/&gt;
      &lt;xsl:template match=&quot;/InputDateTime&quot;&gt;
          &lt;xs:testDate&gt;
              &lt;xsl:variable name=&quot;targetTimeZone&quot; select=&quot;TargetTimeZone/node()&quot;/&gt;
              &lt;xsl:variable name=&quot;utc-timestamp&quot; select=&quot;UTCDateTime&quot;/&gt;
  
              &lt;xsl:variable name=&quot;xslTimeZone&quot;&gt;
                  &lt;xsl:choose&gt;
                      &lt;xsl:when test=&quot;$targetTimeZone = 'CET'&quot;&gt;PT2H&lt;/xsl:when&gt;
                      &lt;xsl:otherwise&gt;Not_Supported&lt;/xsl:otherwise&gt;
                  &lt;/xsl:choose&gt;
              &lt;/xsl:variable&gt;
  
              &lt;xsl:variable name=&quot;tz-timestamp&quot;
                  select=&quot;adjust-dateTime-to-timezone($utc-timestamp, xs:dayTimeDuration($xslTimeZone))&quot;/&gt;
              &lt;date UTC_timestamp=&quot;{$utc-timestamp}&quot;&gt;
                  &lt;cet CET_timestamp=&quot;{$tz-timestamp}&quot;&gt;
                      &lt;xsl:value-of
                          select=&quot;format-dateTime($tz-timestamp, '[M,2]/[D,2]/[Y,4] [h]:[m]:[s] [P]', 'de', (), 'de')&quot;
                      /&gt;
                  &lt;/cet&gt;
              &lt;/date&gt;
          &lt;/xs:testDate&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  <p>Takes e.g. this input XML file:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;InputDateTime&gt;
      &lt;TargetTimeZone&gt;CET&lt;/TargetTimeZone&gt;
      &lt;UTCDateTime&gt;2019-11-15T09:15:00Z&lt;/UTCDateTime&gt;
  &lt;/InputDateTime&gt;
  </code></pre>
  <p>And produces an proper output:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;xs:testDate xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
     &lt;date UTC_timestamp=&quot;2019-11-15T09:15:00Z&quot;&gt;
        &lt;cet CET_timestamp=&quot;2019-11-15T11:15:00+02:00&quot;&gt;11/15/2019 11:15:00 a.m.&lt;/cet&gt;
     &lt;/date&gt;
  &lt;/xs:testDate&gt;
  </code></pre>
  <p>Can anybody help me how to convert from any Java time zone like 'CET' to xslt duration like 'PT2H' without having all this manually maintained?</p>
  <p>Thanks &amp; Regards Marco</p>