Get Date In XML

I would like to know if there is a way to get the date using xml, or if there is some way to get the date via javascript or something. Because I need to be able to compare the current date to one in the document is the XSL if statement. Any ideas?
Who is Participating?
rdcproConnect With a Mentor Commented:
Linux is the operating system...the question is, what XSLT processor are you using?  When you mentioned Javascript, I used MSXML as a generalized example.  Many XSLT processors use extension functions, some of them natively. Even Saxon, which doesn't have a scripting engine, can use java.  Take a look at for a vast library of extensions.    

Personally, as I said, I would probably use the addParameter approach, as the XSLT can be cross-platform that way, and you avoid a few other pitfalls.  It's probably faster, too.  Consult your XSLT processor documentation on the syntax for this.

Mike Sharp
Using Extension functions it's possible.  This example uses MSXML:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
      <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
      <msxsl:script language="JScript" implements-prefix="dates">
                  function getDate() {
                        var oDate = new Date();
                        return oDate.getFullYear() + "-" + (oDate.getMonth() + 1) + "-" + oDate.getDate();
      <xsl:template match="/">
            <h2>Today's Date</h2>
            <xsl:value-of select="dates:getDate()"/>

However, I think it's much better to set the date as a parameter externally, using the addParameter() method or whatever similar mechanism your processor has.  In MSXML, it would be:

var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0");
var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
var xslProc;
xslDoc.async = false;
xslDoc.resolveExternals = false;
xslt.stylesheet = xslDoc;
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
xmlDoc.async = false;
xmlDoc.resolveExternals = false;

date = new date();

if (xmlDoc.parseError.errorCode <> 0) {
   var myErr = xmlDoc.parseError;
   alert("You have error " + myErr.reason);
} else {
   xslProc = xslt.createProcessor();
   xslProc.input = xmlDoc;
   xslProc.addParameter("param1", date.toDateString());

Extension functions are a security issue, and in some platforms, code that uses them must run with elevated privileges. But they work.  They are not necessarily portable across platforms.

Mike Sharp
gf3Author Commented:
Sorry I didnt mention this earlier but this application will be linux based. So I don't believe that I have access to MSXML. Is there another way to do this?
gf3Author Commented:
Thanks for the help, really sorry about the huge delay. I forgot about and it and i came over it again while cleaning up my inbox. Thanks again for the help!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.