Hello everyone,
Recently i came up with a requirement where i need to calculate date difference between current date and some old date, For same i wrote a XSLT which will help you to do same.
One main thing, You need to use "version="2.0"" version for XSLT because we are going to use some advance functions which are not available in 1.0.
<xsl:template match="/">
<ns0:cacheData>
<ns0:differenceTime>
<xsl:call-template name="timeDifference">
<xsl:with-param name="date1" select="xp20:current-dateTime()"/>
<xsl:with-param name="date2" select="/ns0:cacheData/ns0:inserDateTime"/>
</xsl:call-template>
</ns0:differenceTime>
</ns0:cacheData>
</xsl:template>
<xsl:template name="timeDifference">
<xsl:param name="date1"/>
<xsl:param name="date2"/>
<!-- P6240DT5H13M6.622S, Hour is 0 P3DT53M42.321S , With day 6DT1H11M25S-->
<xsl:variable name="dateDifefrence" select="(xsd:dateTime($date1) - xsd:dateTime($date2))"/>
<xsl:variable name="dateDifefrence1" select="substring-after(string($dateDifefrence),'P')"></xsl:variable>
<xsl:value-of select="concat(substring-before(string($dateDifefrence1),'.'),'S')"></xsl:value-of>
</xsl:template>
</xsl:stylesheet>
When you test this XSLT, below will be result.
Source:
<?xml version="1.0" encoding="UTF-8" ?>
<cacheData xmlns="http://www.veevaCacheCommon.org">
<inserDateTime>2018-06-12T00:34:40.791</inserDateTime>
<differenceTime>0</differenceTime>
</cacheData>
Result:
<?xml version = '1.0' encoding = 'UTF-8'?>
<ns0:cacheData xmlns:jca="http://xmlns.oracle.com/pcbpel/wsdl/jca/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:ns0="http://www.veevaCacheCommon.org">
<ns0:differenceTime>T4H0S</ns0:differenceTime>
</ns0:cacheData>
Recently i came up with a requirement where i need to calculate date difference between current date and some old date, For same i wrote a XSLT which will help you to do same.
One main thing, You need to use "version="2.0"" version for XSLT because we are going to use some advance functions which are not available in 1.0.
<xsl:template match="/">
<ns0:cacheData>
<ns0:differenceTime>
<xsl:call-template name="timeDifference">
<xsl:with-param name="date1" select="xp20:current-dateTime()"/>
<xsl:with-param name="date2" select="/ns0:cacheData/ns0:inserDateTime"/>
</xsl:call-template>
</ns0:differenceTime>
</ns0:cacheData>
</xsl:template>
<xsl:template name="timeDifference">
<xsl:param name="date1"/>
<xsl:param name="date2"/>
<!-- P6240DT5H13M6.622S, Hour is 0 P3DT53M42.321S , With day 6DT1H11M25S-->
<xsl:variable name="dateDifefrence" select="(xsd:dateTime($date1) - xsd:dateTime($date2))"/>
<xsl:variable name="dateDifefrence1" select="substring-after(string($dateDifefrence),'P')"></xsl:variable>
<xsl:value-of select="concat(substring-before(string($dateDifefrence1),'.'),'S')"></xsl:value-of>
</xsl:template>
</xsl:stylesheet>
When you test this XSLT, below will be result.
Source:
<?xml version="1.0" encoding="UTF-8" ?>
<cacheData xmlns="http://www.veevaCacheCommon.org">
<inserDateTime>2018-06-12T00:34:40.791</inserDateTime>
<differenceTime>0</differenceTime>
</cacheData>
Result:
<?xml version = '1.0' encoding = 'UTF-8'?>
<ns0:cacheData xmlns:jca="http://xmlns.oracle.com/pcbpel/wsdl/jca/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:ns0="http://www.veevaCacheCommon.org">
<ns0:differenceTime>T4H0S</ns0:differenceTime>
</ns0:cacheData>
Comments
Post a Comment