xsl-list
[Top] [All Lists]

Re: Date formatting using XSLT extensions functions

2003-04-28 21:57:26
http://www.topxml.com/code/default.asp?p=3&id=v20021212030100


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




"Kaine Varley" <kaine(_dot_)varley(_at_)getrealsystems(_dot_)com> wrote in 
message
news:D95333E1DFE4D511B30500065B39139B36EC84(_at_)GETREAL7(_dot_)(_dot_)(_dot_)
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






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