I continue for about 5 hours, trying exactly EVERY Google example found using the serach term "xml xslt to calculate the number of days between dates" that I can find to just take two dates from the "date". xml "and calculate the days between dates in the format" YYYY-MM-DD " (the example below does not have this format, but this is the only format I need)
I finally found this page :: https://forums.oracle.com/thread/2432132
Where the solution can be checked at: http://xslttest.appspot.com/
But, saving "date.xml / date.xslt" on a local host trying to open a page in Internet Explorer, Google Chrome or Firefox either shows an error or nothing at all, and, as always, there is no information about what is wrong . The same thing happens when the file is on a web server.
So why can't I try a simple example that I found that everyone is talking, has a solution, or what am I doing wrong?
The XML file from the above example:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="date.xslt"?>
<root>
<date1>2012-01-11T00:00:00.000-05:00</date1>
<date2>2012-01-15T00:00:00.000-05:00</date2>
</root>
XSLT file from the above example:
<?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"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:template match="/">
<xsl:variable name="date1" select="xs:dateTime(/root/date1)"/>
<xsl:variable name="date2" select="xs:dateTime(/root/date2)"/>
<xsl:value-of select="fn:days-from-duration($date2 - $date1)"/>
</xsl:template>
</xsl:stylesheet>
By adding this to the XSLT verifier, it shows the correct value of "4" days between the two dates.
, , , . , .