|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Date conversion
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






