can i change dateformat in XSL

I have an XSL stylesheet which gets its data from an XML document.

One of the fields to be displayed is a date field. The xml data has the date in format dd-mm-yyyy. Can I do anything so that the XSL changes this format to dd-MMM-yy ?

So 01-01-2001 should display as 01-Jan-2001 !

Who is Participating?
djokovConnect With a Mentor Commented:
In general, YES, but exactly how to do that depends on your xsl code. post it here to see what could be done.
it will be something like:

<xsl:template name="ChangeMonth">
<xsl:param name="Month"/>  <!-- here you will pass month 1-12 -->
<xsl:when test="$Month = '1'">
<xsl:value-of select="Jan"/>
<xsl:when test="$Month = '2'">
<xsl:value-of select="Feb"/>
<xsl:when test="$Month = '12'">
<xsl:value-of select="Dec"/>
<xsl:value-of select="Unrecognized Month!!!"/>
enkay022798Author Commented:
I have been experimenting and yes, djokov, what you suggested will work fine.

Nevertheless, I was wondering if I could simplify this !

I tried to write a function which will do this using

<xsl:script><![CDATA[ tags. When I put this into my XSL, I get returned nothing !!! It doesnt matter wha I put in the function.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"

<xsl:script language="VBScript"><![CDATA[
function GetMeThis()
     GetMeThis = "date"
end function

<xsl:template match="/">

I have ripped off the other xsl tags as of now but no matter what ...
This gets me nothing !!!
enkay022798Author Commented:

I want to leave this Q open for a lil more time. I would like to see some more suggestions, else I will use what you have suggested and award you the points.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Yes, ok, but if it should be plain xslt, i don't think there is other way... however, let us see what other guys will offer.

Wayne BradneyIndependent ConsultantCommented:

If you're going to need to change the format in the future, or maybe have different formats for different people, you might consider using extensions (this is a string replace example, but you'll get the idea):

<xsl:stylesheet xmlns:xsl=""
    <xsl:output method="xml" indent="yes"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="/">
    <xsl:template match="test[@att]">
         <xsl:variable name="str" select="@att"/>
         <xsl:variable name="find" select="_string_"/>
         <xsl:variable name="sub" select="_other_"/>
         <xsl:variable name="repl" select="java:Replacer.replace(string($str), string($find), string($sub))"/>
              <xsl:attribute name="att"><xsl:value-of select="$repl"/></xsl:attribute>

And then you'd write a class Replacer with a method:

public static String replace(String, String, String)

that does whatever you like (in your case date formatting).

enkay022798Author Commented:
Thank you everyone !
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.