Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

format and display datetime in xslt

Tags:

xml

xslt

xpath

I have an XML with datetime data:

<A>
    <StartDate>2011-11-01T00:00:00</StartDate>
    <EndDate>2011-11-30T00:00:00</EndDate>
    <IsRecurring>false</IsRecurring>
</A>

I need to get in xslt only the dates in the following format:

01/11/2011 - 30/11/2011

When I do:

<xsl:value-of select="A/StartDate/"> - <xsl:value-of select="A/EndDate/">

I get this:

2011-11-01T00:00:00 - 2011-11-30T00:00:00

How can I display it properly?

like image 826
Naor Avatar asked Oct 18 '11 10:10

Naor


People also ask

How can I change the date format in XML?

Can use the following conversion code to convert UTC format string to any other DateTime format. string result = Convert. ToDateTime("2011-02-04T00:00:00+05:30"). ToString("MM/dd/yyyy h:mm:ss tt");

What is XSLT format?

XSLT (Extensible Stylesheet Language Transformations) is a language originally designed for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, PostScript and PNG.


1 Answers

Look at XPath string functions: substring, substring-before and etc.

Reference: http://www.w3.org/TR/xpath/#section-String-Functions

<xsl:variable name="dt" select="'2011-11-01T12:13:59'"/>

        <xsl:value-of select="concat(
                      substring($dt, 9, 2),
                      '/',
                      substring($dt, 6, 2),
                      '/',
                      substring($dt, 1, 4)
                      )"/>
like image 191
Kirill Polishchuk Avatar answered Nov 02 '22 00:11

Kirill Polishchuk