Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hello friends,

i have below code of xslt. how can i change the date formate in xslt.?

now it's returning in "DD/MON/YY" formate.but i want it in "DD/MM/YYYY" formate.

i have tried code which is in commented part...
See the below code....

HTML
<xsl:element name="{$rowName}">
    <xsl:for-each select="$fieldset[@name = $rowField]/s:AttributeType">
        <xsl:variable name="fieldname" select="@name" />
        <xsl:variable name="dataType" select="$fieldset[@name = $rowField]/s:AttributeType[@name=$fieldname]/s:datatype/@dt:type" />
        <xsl:variable name="fieldvalue">
            <xsl:choose>
               <xsl:when test="$dataType = 'dateTime'">

                 <xsl:value-of select="substring($row/@*[name()=$fieldname], '1', '2')"/>

        <!-- i have tried below code to get date in  MM formate.. but... :( -->

                <!--<xsl:variable name="mm">
                    <xsl:value-of select="substring($row/@*[name()=$fieldname],4,2)" />
                </xsl:variable>
                <xsl:value-of select="$mm"/> -->

               </xsl:when>
               <xsl:otherwise>
                 <xsl:value-of select="$row/@*[name()=$fieldname]"/>
               </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:element name="{$fieldname}"><xsl:value-of select="$fieldvalue" /></xsl:element>
        <!--xsl:attribute name="{$fieldname}"><xsl:value-of select="$fieldvalue" /></xsl:attribute-->
    </xsl:for-each>
    <!--RECURSIVELY CALL THIS TEMPLATE IF IT CONTAINS ANY CHILD ELEMENTS-->
    <xsl:apply-templates select="*" />
</xsl:element>


Thanx in advance....
Posted
Updated 16-Jul-12 21:06pm
v3

1 solution

Try this way:
C#
string ms:format-date(string datetime, string format [,locale])

This will work for you:
C#
<xsl:value-of select="ms:format-date(., 'dd/MM/yyyy')" xmlns:xsl="#unknown" />

Refer DateFormats: http://msdn.microsoft.com/en-us/library/ms256099.aspx[^]

Have a look on example:
XSLT DateTime Formatting[^]

And a similar example to your question:
xsl format date dd/MM/yyyy[^]

Also check this one:
Formatting Dates and Times[^]
Here three functions are provided to represent dates and times as a string, using the conventions of a selected calendar, language, and country.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900