[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


How to get current date and time of system using XSLT 1.0

Posted on 2011-03-15
Medium Priority
Last Modified: 2012-05-11
    I want to add the current date and time.
What I conclude that its not possible using xslt 1.0 but you can retrieve the system date time.
how that can be done? does it depend on hardware which allow to send date and time information?
Question by:SANbuddies
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
LVL 60

Expert Comment

by:Geert Bormans
ID: 35140012
No, that is something XSLT1 simply can't do

here are your options

- pass a parameter in from outside the XSLT. If you run the XSLT from a programming langiuage, fetch the current date from the programming language and pass it on

- use EXSLT extensions http://www.exslt.org/date/functions/date-time/index.html
supported for Xalan, Saxon and some others
This restricts the number of XSLT processors you can use

- use an extension language for building an extension function yourself
Depends even more on the browser
would be Javascript or C# for msxml, would be java for xalan and saxon (but for those you could usethe previous method anyway)

- if you need to run the XSLT in a browser, call the XSLT from javascript and use the first method

re-check your requirements for XSLT1.
I have found many projects that claimed to requirer XSLT1, but that were easy to turn into XSLT2 projects
XSLT2 has the functionality in house
LVL 60

Expert Comment

by:Geert Bormans
ID: 35140018
Tell me which method you prefer (and most importantly which processor you use)
and I will give you an example

Author Comment

ID: 35145188
well I am not using XSLT in a browser, I am using the XSLT against xml file to fetch some data according to the requirement.
Is possible that I use the VB code in same XSLT file.
Public Function GetDate() As String
  {    body of the function get date


XSLT function
<xsl:variable name="MasterDate" select="vb:GetDate()" />

What is your idea about above?
If you have a better solution, you are welcome to share.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 60

Expert Comment

by:Geert Bormans
ID: 35145194
well, that would be an extension function,
I am not sure about VB, there is a possibility that you can get this to work (but more code is needed then) using VBScript and msxml

You haven't answered my questions
- how do you execute the XSLT (I know it is not the browser, but what is it then), do you execute the XSLT from VB?
- which processor are you using

Author Comment

ID: 35145791
I am actually not quite sure which processor we are using.
we are calling the xslt in a program but I am not sure which processor its using the program is either build in VB or any .net technology I am sure.
Is it very important to know the processor?
LVL 60

Expert Comment

by:Geert Bormans
ID: 35145817
Yes, it is very important to know the processor if you need to build extension functions.

If you are calling the XSLT from VB or .Net then you are using msxml

I will look for an example using extension functions,
that will work for msxml only

but I would simply pass the date as a parameter

have a global parameter in the XSLT
<xsl:param name="cur-time"/>
as a direct child of the xsl:stylesheet element

and from the VB code pass the parameter with the transform
(using something like "addParameter", but that depends on the XSLT calling code you are using)
LVL 60

Accepted Solution

Geert Bormans earned 500 total points
ID: 35148488
Here is what you can likely do

you will need
- msxsl namespace declared
- a random namespace declared for your function (I used exslt date here)
- an msxsl:script block in your stylesheet that implements the javascript function. Note that you need to indicate the namespace prefix here and that you need to use it in the function call
and there is a language specification. I am quite certain that it works for VBScript too. SAme approach

But still... I would go the passing parameter way

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                extension-element-prefixes="date msxsl">

<msxsl:script language="JScript" implements-prefix="date">
	function date(){
		var oDate = new Date();
		var ret = "";
		var m = oDate.getMonth() + 1;
	    var mm = m < 10 ? "0" + m : m;
		ret = ret + mm + "/";
		var d = oDate.getDate();
		var dd = d < 10 ? "0" + d : d;
		ret = ret + dd + "/";
		ret = ret + oDate.getFullYear();
		return ret;
<xsl:template match="/">
	<xsl:value-of select="date:date()"/>


Open in new window


Author Comment

ID: 35178688
I am already using a VB function like this
<msxsl:script language="VB" implements-prefix="vb">
  Public Function GetInterfaceDef(byVal name as string) As String

What you think, using existing VB would be better to generate Date? as compare to have an additional JScript?

LVL 60

Expert Comment

by:Geert Bormans
ID: 35178934
Well, my argument for getting the date outside the XSLT and then pass it in, is mainly based on keeping the XSLT processor independent.
If you already have a VB function implemented in your XSLT,
you are bound to msxml already,
so I would suggest that you'd better create another VB function for the current date.
You can do that inside the same msxsl:script block
There is no need to merge vB and JScript blocks, if you are comfortable with VB, continue using it (don't merge three languages if two will do :-)

I by the way did not know that VB was an option for msxsl:script

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question