« Tokenizing WSDL imports while deploying to mutliple environments | Main | Deployed BPEL Process do not show up in BPEL Console on startup »

Subtracting 2 dateTime values into a duration using XPath 2.0

Here is a simple XSLT that allows you to subtract two xsd:dateTime values into a xsd:duration value.


The given XSLT uses XPath 2.0. Hence to get it to work, ensure that the "version" attribute on the <xsl:stylesheet> element is set to "2.0". I have used Oracle BPEL 10.1.3.1 for this illustration.


XSL Source


<xsl:stylesheet version="2.0" xmlns:ns1="http://www.output.org"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:ns0="http://www.input.org"
                exclude-result-prefixes="xsl xsd ns0 ns1">
  <xsl:template match="/">
    <ns1:output>
      <ns1:durationValue>
        <xsl:value-of select="(xsd:dateTime(/ns0:input/ns0:date1) - xsd:dateTime(/ns0:input/ns0:date2))"/>
      </ns1:durationValue>
    </ns1:output>
  </xsl:template>
</xsl:stylesheet>


Input


<?xml version="1.0" encoding="UTF-8" ?>
<input xmlns="http://www.input.org">
   <date1>2007-07-17T12:50:28.256</date1>
   <date2>2007-07-18T12:52:28.257</date2>
</input>


Output


<?xml version = '1.0' encoding = 'UTF-8'?>
<ns1:output xmlns:ns1="http://www.output.org">
   <ns1:durationValue>-P1DT2M0.1S</ns1:durationValue>
</ns1:output>


 

Comments (1)

Eric Elzinga:

Nice post!
We have been struckling with this too in my current project.
Better skip the graphical xsl mapper of bpel/esb, otherwise all the handmade-changes are gone again.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About This Entry

This page contains a single entry from the blog posted on July 18, 2007 3:01 PM.

The previous post in this blog was Tokenizing WSDL imports while deploying to mutliple environments.

The next post in this blog is Deployed BPEL Process do not show up in BPEL Console on startup.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type and Oracle