Solved

can  i change dateformat in XSL

Posted on 2001-07-10
6
296 Views
Last Modified: 2008-03-17
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
0
Comment
Question by:enkay022798
[X]
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
  • 3
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
djokov earned 50 total points
ID: 6269931
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:choose>
<xsl:when test="$Month = '1'">
<xsl:value-of select="Jan"/>
</xsl:when>
<xsl:when test="$Month = '2'">
<xsl:value-of select="Feb"/>
</xsl:when>
...
<xsl:when test="$Month = '12'">
<xsl:value-of select="Dec"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="Unrecognized Month!!!"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
0
 
LVL 2

Author Comment

by:enkay022798
ID: 6270017
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="http://www.w3.org/1999/XSL/Transform" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"
version="1.0">

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

<xsl:template match="/">
<xsl:eval>GetMeThis()</xsl:eval>
</xsl:template>
</xsl:stylesheet>

I have ripped off the other xsl tags as of now but no matter what ...
This gets me nothing !!!
0
 
LVL 2

Author Comment

by:enkay022798
ID: 6270022
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.
0
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 2

Expert Comment

by:djokov
ID: 6270127
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.
0
 
LVL 6

Expert Comment

by:wbradney
ID: 6270320
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="java"
               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.replace(string($str), string($find), string($sub))"/>
         <test>
              <xsl:attribute name="att"><xsl:value-of select="$repl"/></xsl:attribute>
         </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
0
 
LVL 2

Author Comment

by:enkay022798
ID: 6276972
Thank you everyone !
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XSLT Help 12 37
what are list of ebay api errors 1 47
Help with a Python script converting xml to csv 4 71
Extracting nodes  using classical ASP 3 40
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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