First we have to add namespaces, then write the code.
XSLT File : (datetime.xslt)
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:myExtension="urn:myExtension"
exclude-result-prefixes="msxsl myExtension">
<xsl:output method="xml" indent="yes"/>
<msxsl:script implements-prefix="myExtension" language="C#">
<![CDATA[
public string FormatDateTime(string xsdDateTime, string format)
{
DateTime date = DateTime.Parse(xsdDateTime);
return date.ToString(format);
}
]]>
</msxsl:script>
<xsl:template match="Date">
<formattedDate>
<xsl:value-of select="myExtension:FormatDateTime(self::node(), 'd')"/>
</formattedDate>
</xsl:template>
</xsl:stylesheet>
XML File: (datetime.xml)
<?xml version="1.0" encoding="utf-8" ?>
<Date>2007-11-14T12:01:00</Date>
CALL on program.aspx.cs page
Xml1.DocumentSource = MapPath("datetime.xml");
Xml1.TransformSource = MapPath("datetime.xslt");
OUTPUT:
11/14/2007
No comments:
Post a Comment