I have scenario which I would like to count as one day if the dates are same.
<wd:Date>2021-08-18</wd:Date>
<wd:Date>2021-08-18</wd:Date>
How can I achieve this using XSLT. So, I want count this a one day if the Date is same.
I have scenario which I would like to count as one day if the dates are same.
<wd:Date>2021-08-18</wd:Date>
<wd:Date>2021-08-18</wd:Date>
How can I achieve this using XSLT. So, I want count this a one day if the Date is same.
You could:
xs:date() to evaluate those values as xs:datexs:dateTimeDurationdays-from-duration() to return that number of days (which would be zero)abs(), such that we don't have to worry about which date was on the left or right hand side and positive or negative values1 to that valueThis stylesheet:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:template match="/">
<xsl:text>Days: </xsl:text>
<xsl:value-of select="abs(days-from-duration(xs:date(/*/*:Date[1]) - xs:date(/*/*:Date[2]))) + 1"/>
</xsl:template>
</xsl:stylesheet>
Applied to this XML file:
<wd:example xmlns:wd="wd">
<wd:Date>2021-08-18</wd:Date>
<wd:Date>2021-08-18</wd:Date>
</wd:example>
Produces this output:
Days: 1