Reputation: 669
I have a scenario in which we need to increment 1 day in existing date. Like In <subscriptionDate>2015-05-06</subscriptionDate>
I want to increase 1 day and map its value to <terminationDate>2015-05-07</terminationDate>
. How can I achieve this using XSLT. So, all date constraints should also be handled. like if day is 31 then increment in month.
<Subscription code="12345678R1">
<userAccount>40000005b</userAccount>
<offerTemplate>Test</offerTemplate>
<subscriptionDate>2015-05-06</subscriptionDate>
<terminationDate></terminationDate>
</Subscription>
Upvotes: 5
Views: 24225
Reputation: 11
I can add that I was banging away for awhile before I realized the xs: namespace was missing. I usually only use the xsl: functions.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
If it isn't declared the xs:date function and xs:dayTimeDuration won't work.
Also this is a resource from ibm on the types
https://www.ibm.com/docs/en/i/7.2?topic=system-date-time-data-types
Upvotes: 1
Reputation: 167571
Assuming XSLT 2.0 you can add a duration to an date e.g.
<xsl:template match="terminationDate">
<xsl:copy>
<xsl:value-of select="xs:date(preceding-sibling::subscriptionDate) + xs:dayTimeDuration('P1D')"/>
</xsl:copy>
</xsl:template>
See http://xsltransform.net/pPqsHTP.
Upvotes: 6