2

I have a following date scenario, in which i want to increment in date, But the date format is of as following: 2015-05-03T00:00:00Z. I only want to increment in date of one day. So that if it reaches 31 then the month should be updated. I saw an existing question but the solution is not working on my scenario.

XML:

<?xml version="1.0" encoding="UTF-8"?>
<rootElement>

    <TestDate>2015-05-03T00:00:00Z</TestDate>
</rootElement>

XSLT:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   version="2.0">


    <xsl:template match="rootElement">
      <TransformDate>
          <xsl:value-of select="substring(TestDate,1,10)" />
      </TransformDate>
    </xsl:template>
</xsl:transform>

Result:

    <?xml version="1.0" encoding="UTF-8"?>
<TransformDate>2015-05-03</TransformDate>

ExpectedResult:

<?xml version="1.0" encoding="UTF-8"?>
<TransformDate>2015-05-04T00:00:00Z</TransformDate>
Community
  • 1
  • 1
omer khalid
  • 855
  • 1
  • 12
  • 39
  • 2
    "*I saw an existing question but the solution is not working on my scenario.*" Why not? I don't see that you have tried to implement it. – michael.hor257k May 12 '15 at 10:15

1 Answers1

5

try with this stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xsl:strip-space elements="*"/>
    <xsl:output indent="yes" omit-xml-declaration="yes"/>

    <xsl:template match="rootElement">
        <xsl:element name="TransformDate">
            <xsl:value-of select="xs:dateTime(TestDate) + xs:dayTimeDuration('P1D')"/>
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>
Joel M. Lamsen
  • 7,143
  • 1
  • 12
  • 14