How to Increment 1 day in Date using XSLT
Asked Answered
C

2

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>
Consign answered 8/5, 2015 at 9:59 Comment(1)
Please select either XSLT 1.0 or XSLT 2.0, not both. Makes a huge difference in this case.Steak
D
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.

Dirac answered 8/5, 2015 at 10:21 Comment(2)
@Martin, How can we increment the date if the format is of as following: 2015-05-03T00:00:00ZNafis
@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.Dirac
B
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

Biogeochemistry answered 3/11, 2022 at 9:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.