enkay022798
asked on
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 !
Thanx!
Enkay
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 !
Thanx!
Enkay
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
djokov,
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.
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.
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.
cheers.
cheers.
enkay,
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="http://www.w3.org/1999/XSL/Transform"
xmlns:java="http://xml.apache.org/xslt/java"
exclude-result-prefixes="j ava"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<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.repl ace(string ($str), string($find), string($sub))"/>
<test>
<xsl:attribute name="att"><xsl:value-of select="$repl"/></xsl:attr ibute>
</test>
</xsl:template>
</xsl:stylesheet>
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).
Regards,
WMB
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="http://www.w3.org/1999/XSL/Transform"
xmlns:java="http://xml.apache.org/xslt/java"
exclude-result-prefixes="j
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<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.repl
<test>
<xsl:attribute name="att"><xsl:value-of select="$repl"/></xsl:attr
</test>
</xsl:template>
</xsl:stylesheet>
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).
Regards,
WMB
ASKER
Thank you everyone !
ASKER
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="http://www.w3.org/1999/XSL/Transform" xmlns:rs="urn:schemas-micr
version="1.0">
<xsl:script language="VBScript"><![CDA
function GetMeThis()
GetMeThis = "date"
end function
]]>
</xsl:script>
<xsl:template match="/">
<xsl:eval>GetMeThis()</xsl
</xsl:template>
</xsl:stylesheet>
I have ripped off the other xsl tags as of now but no matter what ...
This gets me nothing !!!