0

I am comparing dates in xsl:stylesheet version="1.0" and if date difference is greater than 30 days than update Pkg variable by 0. But it seems its not working.

<xsl:variable name="Packagedate" select="//segment[@name='Date']/value"></xsl:variable> 
<xsl:variable name="date" select="substring($Packagedate, 5, 2)"/>-<xsl:value-of select="substring($Packagedate, 7)"/>-<xsl:value-of select="substring($Packagedate, 1, 4)"></xsl:variable>
<xsl:variable name="CurrentDate" select="format-dateTime(current-dateTime(),'[Y0001]-[M01]-[D01]')"></xsl:variable>

<xsl:when test="days-from-duration(xs:date($CurrentDate)- xs:date('$date)) > 30">
<div class="fieldvalue">
<xsl:variable name="Pkg"></xsl:variable>
<xsl:value-of select='0'/>
</div>
</xsl:when>
  • *"it seems its not working"* is not a good description of a problem. In any case, the code you show requires a processor that supports XSLT 2.0. – michael.hor257k May 05 '20 at 01:01
  • I am getting parsing error and days-from-duration is not supported in XSLT 1.0 which function is supported whi can help in comparing date – vkatara May 05 '20 at 01:03
  • There are no date functions in XSLT 1.0. See here how you can compare dates: https://stackoverflow.com/a/22377178/3016153. Some XSLT 1.0 processors support the EXSLT `date:difference()` extension function: http://exslt.org/date/functions/difference/index.html – michael.hor257k May 05 '20 at 01:10
  • And since you also seem to need the current date: https://stackoverflow.com/a/26628225/3016153 – michael.hor257k May 05 '20 at 01:15
  • Some basic advice: diagnosing problems always starts with the symptoms. So give a clear description of the symptoms. Show us the error message. OK, this one is so basic that experienced users can spot the error a mile off without seeing the message; but that's not the case in general. – Michael Kay May 05 '20 at 06:54
  • To expand on this, I think there are two reasons people don't tell us the error message. One is that they don't understand it, and assume that no-one else will either. This is not the case; the reason you don't understand the error message is that you haven't yet understood the concepts it relies on. The second reason is that you're not actually seeing the error message, e.g. you haven't worked out where to find it in the browser developer console. In that case we can help you to help yourself. – Michael Kay May 05 '20 at 07:03

1 Answers1

1

You are using functions such as days-from-duration() and xs:date() that are only available in XSLT 2.0+, but you are running your stylesheet under an XSLT 1.0 processor. Options that might be available to you include:

  • Upgrading to a different XSLT processor

  • Using the add-on date/time library at exslt.org

  • Calling out to functions in your host programming language (e.g. Java or C#).

Michael Kay
  • 156,231
  • 11
  • 92
  • 164