XSLT 1.0
Hi,
I need to return the current system Date/Time via javascript from one XSLT file to another.
I have included both of my XSLT programs below:
1. XML conversion script (Calling file)
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mi="http://schemas.microsoft.com/dynamics/2006/02/documents/MovementDelivery" xmlns:date="//vee1/E:/FTPRoot/trans/xsl/CALjs-functions">
<!-- Import the CAL js-functions template -->
<xsl:import href="CALjs-functions.xslt"/>
<xsl:variable name="str1" select="Envelope/Body/mi:MovementDelivery/mi:VCTMovements[@class='entity']/mi:RecVersion"/>
<xsl:variable name="strSrceEndPt" select="./Envelope/Header/SourceEndpoint"/>
<xsl:variable name="strDocPurpose" select="Envelope/Body/mi:MovementDelivery/mi:DocPurpose"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="/">
<xsl:call-template name="DelvyNotif"/>
</xsl:template>
<xsl:template name="DelvyNotif">
<xsl:element name="DocumentCreated">
<xsl:attribute name="DateTimeType">Document Created</xsl:attribute>
<xsl:value-of select="js-function:DateTimeNow()"/>
</xsl:element>
</xsl:template>
<xsl:template name="copy">
<xsl:copy>
<xsl:for-each select="@*">
<xsl:copy/>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
2. XSLT containing Javascript function (Called file)
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" extension-element-prefixes="js-function" xmlns:js-function="//vee1/E:/FTPRoot/trans/xsl/CALjs-functions">
<msxsl:script language="javascript" implements-prefix="js-function">
function DateTimeNow()
{
var now;var year;var month;var monthday;var weekday;var hours;var mins;var secs;var mills;
{
now = new Date();
year = now.getYear();
month = now.getMonth();
monthday = now.getDate();
// weekday is NOT used in the returning value (0 = Sunday, 1 = Monday)
//weekday = now.getDay();
hours = now.getHours();
mins = now.getMinutes();
secs = now.getSeconds();
// 2 Decimal places....
mills = Math.floor(now.getMilliseconds() / 10);
// Original advise was for 1/10th Sec - (i.e. /100) this converts to 1 Dec Place
// (if used, there would be NO use for the 'CDATA' statement - BUT change to mills=mills+"0";).
// 1 Decimal Place....
// mills = Math.floor(now.getMilliseconds() / 100);
{
<![CDATA[if (mills<10)]]>
{
mills="0"+mills;
}
<![CDATA[if (secs<10)]]>
{
secs="0"+secs;
}
<![CDATA[if (mins<10)]]>
{
mins="0"+mins;
}
<![CDATA[if (hours<10)]]>
{
hours="0"+hours;
}
<![CDATA[if (monthday<10)]]>
{
monthday="0"+monthday;
}
// January = 0, December = 11
month=month + 1
<![CDATA[if (month<10)]]>
{
month="0"+month;
}
<![CDATA[if (year<10)]]>
{
year="0"+year;
}
return year + month + monthday + " " + hours + ":" + mins + secs + mills;
}
}
}
</msxsl:script>
</xsl:stylesheet>
When the 1st file tries to execute the value of '
select="js-function:DateTimeNow()"', the following error occurs:
'Error in XPath expression, Invalid prefix'
I've used similar javascript functions within XSLT before, but I can't see where I'm going wrong. Can anyone help please?
Thanks in advance,