Subject: RE: [xsl] Date conversion From: "Robert C. Lyons" <boblyons@xxxxxxxxxx> Date: Wed, 1 Aug 2001 11:30:51 -0400 |
Katie asks: > The format of the date returned in my XML is 17-Dec-2000 07:23:31 > I need to display the date as 12/17/2000. > > How do I do this using xsl? Katie, You can do this as follows: <xsl:variable name="months" select="'JanFebMarAprMayJunJulAugSepOctNovDec'"/> <xsl:template match="date"> <xsl:text>Old date: </xsl:text> <xsl:value-of select="."/> <xsl:text>
</xsl:text> <xsl:variable name="day" select="substring( ., 1, 2 )"/> <xsl:variable name="earlier_months" select="substring-before( $months, substring( ., 4, 3 ))"/> <xsl:variable name="month_number" select="string-length( $earlier_months ) div 3 + 1"/> <xsl:variable name="month" select="format-number( $month_number, '00' )" /> <xsl:variable name="year" select="substring( ., 8, 4 )"/> <xsl:text>New date: </xsl:text> <xsl:value-of select="concat( $month, '/', $day, '/', $year )"/> <xsl:text>
</xsl:text> </xsl:template> Hope this helps. Bob <sig name = 'Bob Lyons' title = 'XML Consultant' company = 'Unidex, Inc.' phone = '+1-732-975-9877' email = 'boblyons@xxxxxxxxxx' url = 'http://www.unidex.com/' product = 'XML Convert: transforms flat files to XML and vice versa' /> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Date conversion, cutlass | Thread | Re: [xsl] Date conversion, Steve Ball |
Re: [xsl] Re: StylishMonkey.com, Robert Koberg | Date | Re: [xsl] Date conversion, Steven . C . Kienle |
Month |