I'm trying to follow the guidance given in this answer: time difference
But don't see why the template method is failing. Perhaps it has something to do with the namespace. And I don't understand my results for the function approach.
Input xml:
<BatchData >
<Line>
<Batch>
<start>2011-12-13T16:15:26</start>
<end>2011-12-13T16:17:27</end>
</Batch>
</Line>
xsl file:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="date"
>
<xsl:include href="date.msxsl.xsl" />
<!-- msxsl.exe myDateTestInput.xml myDateEXSLT.xsl -o dateTestOut.html-->
<!-- java -cp C:\XSL\SaxonHE9-7-0-14J\saxon9he.jar net.sf.saxon.Transform -t -s:myDateTestInput.xml -xsl:myDateEXSLT.xsl -o:dateTestOut.html -->
<xsl:output method="html" />
<xsl:template match="/BatchData/Line/Batch">
<html>
<head>
</head>
<body>
<table >
<tr>
<td>
<xsl:variable name="time-diff-dur">
<xsl:call-template name="date:difference">
<xsl:with-param name="start" select="start" />
<xsl:with-param name="end" select="end" />
</xsl:call-template>
</xsl:variable>
<!-- The above returns a duration formatted string, so convert that to seconds: -->
<xsl:variable name="time-diff-sec">
<xsl:call-template name="date:seconds">
<xsl:with-param name="seconds" select="$time-diff-dur" />
</xsl:call-template>
</xsl:variable>
<!--
<xsl:variable name="time-diff-sec" select="date:seconds(date:difference(start, end))" />
<xsl:value-of select="$time-diff-sec"></xsl:value-of>
-->
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
I used both msxsl and Saxon9he. They both failed on the template approach but Saxon provided some error info at least. This is the errors from using the templates:
Static error at xsl:call-template on line 25 column 51 of myDateEXSLT.xsl: XTSE0650: No template exists named date:difference Static error at xsl:call-template on line 32 column 52 of myDateEXSLT.xsl: XTSE0650: No template exists named date:seconds Warning at xsl:variable on line 31 column 44 of myDateEXSLT.xsl: SXWN9001: A variable with no following sibling instructions has no effect Errors were reported during stylesheet compilation
When I comment out the templates and uncomment the function approach, I get no errors but don't know how to display the result of time-diff-sec as a table-data value. Instead the output is just the 2 datetimes of the input file.
I also used "import" instead of "include" but that didn't make any difference. Is there a difference?
So to summarize the questions:
- what did I do wrong with the template method?
- how do I display the value from the function approach?
- is there a difference between 'import' and 'include'?
Perhaps the former is for pulling it down from a site while the latter is for local resources.
Thanks.
This is the file date.msxsl.xsl. I'll post it here because that exslt.org site seems to be having issues. (rename the extension): date.msxsl.xsl