5

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>
Daniel Haley
  • 51,389
  • 6
  • 69
  • 95
Waqas Ali Razzaq
  • 659
  • 1
  • 5
  • 30

2 Answers2

6

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.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • @Martin, How can we increment the date if the format is of as following: 2015-05-03T00:00:00Z – omer khalid May 12 '15 at 08:48
  • 2
    @omerkhalid, that is a `xs:dateTime` so you can use `xs:dateTime(' 2015-05-03T00:00:00Z') + xs:dayTimeDuration('P1D')` to get a new `xs:dateTime` to which the duration was added. – Martin Honnen May 12 '15 at 11:26
1

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