Solved

Change date format in xslt

Posted on 2009-04-02
3
609 Views
Last Modified: 2013-11-18
Hi,

I'm using xslt to display date from xml
In xml the date is like "2009-02-11T15:55:20.283-08:00" , which i'm reading from xsl.
I want to change the format of date to "02-11-2009" in xsl.


How can i do that

Thanks and Regards
Puneet
XML:
 
<a>
<b id="1">
  <date>2009-02-11T15:55:20.283-08:00</date>
</b>
<b id="2">
  <date>2009-02-21T10:55:20.283-08:00</date>
</b>
 
 
and my xsl is 
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
<html>
<head><title>Oa</title><link rel="stylesheet" type="text/css" />
</head>
<body  bgcolor="#808080">
<TR>
<xsl:for-each select="a/b">
<TD width="10%" align="center"><xsl:value-of select="date"/></TD> 
</TR>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Open in new window

0
Comment
Question by:PuneetKSaxena
[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
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 24047436
try this
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="UTF-8"/>
    <xsl:template match="/">
        <html>
            <head><title>Oa</title><link rel="stylesheet" type="text/css" />
            </head>
            <body  bgcolor="#808080">
                <TR>
                    <xsl:for-each select="a/b">
                        <TD width="10%" align="center">
                            <xsl:value-of select="substring-before(substring-after(date, '-'), '-')"/>
                            <xsl:text>-</xsl:text>
                            <xsl:value-of select="substring-before(substring-after(substring-after(date, '-'), '-'), 'T')"/>
                            <xsl:text>-</xsl:text>
                            <xsl:value-of select="substring-before(date, '-')"/>
                        </TD> 
                        </xsl:for-each>
                </TR>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 

Author Closing Comment

by:PuneetKSaxena
ID: 31565681
Thats perfect.

Thanks a lot
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24047640
welcome
0

Featured Post

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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…

738 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