Reputation: 155
Note: Please don't mark this as duplicate, hear my question out please
I'm completely new here and I've been running down a mental breakdown on getting a simple date difference between 2 dates from past 2 hours, every answer on the internet doesn't seem to work for me.
Can someone please provide exactly what do i have to put in the XML file and what goes in the XSL file to get the simplistic date difference possible?
Every answer out there just throws one segment of the code but with being new I have no idea where and how to implement it so thanks for understanding my issue :) Hope you can help me
Even if you mark this as duplicate, atleast put it in comment what exactly I have to put in XML file and what exactly goes in XSL file
Upvotes: 0
Views: 2463
Reputation: 2167
One of the simplest XSLT 2.0-date-compare is like this:
XML:
<dates>
<date id="1">2016-09-15</date>
<date id="2">2016-09-10</date>
</dates>
XSLT 2.0:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
<xsl:template match="dates">
<xsl:element name="difference">
<xsl:value-of select="days-from-duration(xs:date(date[@id=1]) - xs:date(date[@id=2]))"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
If this does not work, your problem is somewhere other located than the stylesheet. Then you have to state your environment like xslt-processor, software, programming language you are using.
Upvotes: 2