title: Calculating number of days from two dates in XML with XSLT
body: <p>I've been going on for about 5 hours now, trying exactly EVERY example found on Google found with the serach term "xml xslt calculate number of days between dates" that I could find to just take two dates from "date.xml" file and calculating the days between the dates, in format "YYYY-MM-DD" <strong><em>(example below doesn't have this format, but it's the only format I need)</em></strong></p>
  
  <p>I finally found this page:: <a href="https://forums.oracle.com/thread/2432132" rel="noreferrer">https://forums.oracle.com/thread/2432132</a></p>
  
  <p>Where the solution can be verified at: <a href="http://xslttest.appspot.com/" rel="noreferrer">http://xslttest.appspot.com/</a></p>
  
  <p>But, saving the "date.xml/date.xslt" on localhost trying to open the page in Internet Explorer, Google Chrome or Firefox either shows error or nothing at all and as it's always seem to have been - no information what is wrong. The same happens when the file is on a webserver.</p>
  
  <p>So, why can't I try out a simple example that I've found that everyone says has the solution or what am I doing wrong?</p>
  
  <p>XML File from the above example:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;?xml-stylesheet type="text/xsl" href="date.xslt"?&gt;
  
  &lt;root&gt;
      &lt;date1&gt;2012-01-11T00:00:00.000-05:00&lt;/date1&gt;
      &lt;date2&gt;2012-01-15T00:00:00.000-05:00&lt;/date2&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>XSLT File from the above example:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;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"&gt;
  
  &lt;xsl:template match="/"&gt;
      &lt;xsl:variable name="date1" select="xs:dateTime(/root/date1)"/&gt;
      &lt;xsl:variable name="date2" select="xs:dateTime(/root/date2)"/&gt;
      &lt;xsl:value-of select="fn:days-from-duration($date2 - $date1)"/&gt;
  &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Adding this to the XSLT verifier, it shows the right value "4" days between these two dates.</p>
  
  <p>I want to be able to just create a document that actually can do calculations, whether they are dates or numbers but it's seems impossible at this moment. Get number of dates, then do some calculation with that value.</p>