xsl-list
[Top] [All Lists]

Date formatting using XSLT extensions functions

2003-04-28 00:25:44
Hi,

I have an input date in a format like this: 13/03/2003 4:58:32 pm which I'd
like to format into the following: 13 March

I have tried the following two extension functions, without success I'm
afraid. The first uses VBScript and the second JavaScript. I haven't
attempted to convert the month number to a name yet. Are the built script
language functions and objects not available from the extensions?

VBScript version:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:extra="urn:extra-functions">
        <msxml:script xmlns:msxml="urn:schemas-microsoft-com:xslt"
language="VBScript" implements-prefix="extra">
                Function DateFormat(InputDate)
                        If IsDate(InputDate) Then
                                DateFormat = Day(InputDate) & " " &
Month(InputDate)
                        End If
                End Function
        </msxml:script>

        <xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>



        <xsl:template name="format-date">
                <xsl:param name="date-to-format" />


                <xsl:value-of select="extra:DateFormat($date-to-format)" />
        </xsl:template>

</xsl:stylesheet>

 

JavaScript version:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:extra="urn:extra-functions">

        <msxml:script xmlns:msxml="urn:schemas-microsoft-com:xslt"
language="JavaScript" implements-prefix="extra">
                function formatDate(dte){
                        var dateToFormat = new Date(dte);

                        return dateToFormat.getDay() + ' ' +
dateToFormat.getMonth();
                };
        </msxml:script>

        <xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>



        <xsl:template name="format-date">
                <xsl:param name="date-to-format" />


                <xsl:value-of select="extra:formatDate($date-to-format)" />
        </xsl:template>

</xsl:stylesheet>
 

Regards,


Kaine

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list