How to Increment 1 day in Date using XSLT

2019-03-05 08:12发布

问题:

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>

回答1:

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.