Okay, so I'm having trouple with using javascript scripts to perform calculations on my XSLT transformation.
Basically, there is an xml element in the file to be transformed, with attributes startDateTime and endDateTime. All I want to do is subtract the two, and return that value for the user to see.
<event startDateTime = "" endDateTime = "">
<eventOutcome>Fail</eventOutcome>
<event>
Where obviously, everything would be filled in correctly. Then, there is an xslt transformation, that needs to do the math to find the elapsed time.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"> //schemas included here
<msxsl:script language="JScript" implements-prefix="user">
function elapsedTime(start, end) {
return (xmlToDateTime(end).getTime() - xmlToDateTime(start).getTime()) / 1000;
}
function xmlToDateTime(xmlString) {
//a script that works fine
}
</msxsl:script>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="topLevelElement">
<wordDocument>
<body>
<sect>
<p>
<r>
<t><xsl:apply-templates select="event"/> Seconds</w:t>
</r>
</p>
<sect>
<body>
<wordDocument>
</xsl:template>
<xsl:template match="event">
<xsl:value-of select="user:elapsedTime(@startDateTime, @endDateTime)"/>
</xsl:template>
</xsl:stylesheet>
What I want this to do is pass the attributes of event to the javascript function as strings. What it does instead, is pass an object of that Visual Studio identifies as {MS.Internal.Xml.XPathArrayIterator}. The function works fine if I use the strings directly like
<xsl:value-of select="user:elapsedTime(DATETIME', 'DATETIME')
So the problem isn't the javascript itself, but more my ability to send it arguments.
The official MS Documentation is less than helpful.
http://msdn.microsoft.com/en-us/library/533texsx(v=vs.110).aspx
For one, they use C# instead of JS, which I'm not sure the significance of. But they are just passing the name of an element in, no explanation of how it gets that value out.
I also read the FAQ here
http://www./xsl/sect4/N9745.html#d13958e70
And their code doesn't work! It gives the same issue of passing a {MS.Internal.Xml.XPathArrayIterator} instead of a value.
I'm at a loss here, so I'm open to any suggestions. Thanks in advance.