1
votes
<dates>
    <date id="1">2016-09-15</date>
    <date id="2">2019-09-15</date>
</dates>

As displayed above I have to input dates one as the Start date and end date My output should be the difference between and two dates and the result will generate a list of years Result 2017 2018 2019

1
A list of years is one thing, difference another. Also it's not clear what the result should be when both dates are in the same year. - michael.hor257k
Basically, I need a list of years.. and No worries as per my requirement end year is != to start year - user3651338

1 Answers

0
votes

The result you show can be produced by using a recursive named template to enumerate the years:

<xsl:template name="enumerate">
    <xsl:param name="start"/>
    <xsl:param name="end"/>
    <xsl:value-of select="$start" />
    <xsl:if test="$start &lt; $end">
        <xsl:text>&#10;</xsl:text>
        <xsl:call-template name="enumerate">
            <xsl:with-param name="start" select="$start + 1"/>
            <xsl:with-param name="end" select="$end"/>
        </xsl:call-template>
    </xsl:if>
</xsl:template>

In your example you would call the template as:

<xsl:template match="dates">
    <xsl:call-template name="enumerate">
        <xsl:with-param name="start" select="substring(date[@id=1], 1, 4) + 1"/>
        <xsl:with-param name="end" select="substring(date[@id=2], 1, 4)"/>
    </xsl:call-template>
</xsl:template>