Subject: Re: [xsl] Date Formating From: Elizabeth Barham <lizzy@xxxxxxxxxxxxxxxxx> Date: 12 Jan 2003 09:21:05 -0600 |
Arthur writes: > I'm transforming an xml file that gives me a nicely formatted report > (html 80 odd pages). > Part of the transform uses format-number() for decimal places etc. > > one of the elements in the xml, is a date > <date-created>2003-01-12</date-created> > > How do you transform this to 12-Jan-03 ? I generally like to use look-up elements for this type of thing. In version 1.1 you can place elements like: <data> <month-names> <month sequence="1">Jan</month> <month sequence="2">Feb</month> <month sequence="3">Mar</month> <month sequence="4">Apr</month> <month sequence="5">May</month> <month sequence="6">Jun</month> <month sequence="7">Jul</month> <month sequence="8">Aug</month> <month sequence="9">Sep</month> <month sequence="10">Oct</month> <month sequence="11">Nov</month> <month sequence="12">Dec</month> </month-names> </data> in the stylesheet itself and use the "document('')" function. I generally place this type of info in a separate file that is consulted during the transformation. For this example, assume the above contents are in a file entitled "data.xml": <xsl:template match="date-created"> <!-- get each separate part of the date: YYYY-MM-DD --> <xsl:variable name="year"> <xsl:value-of select="substring(., 3, 2)"/> </xsl:variable> <xsl:variable name="month"> <xsl:value-of select="number(substring(., 6, 2))"/> </xsl:variable> <xsl:variable name="day"> <xsl:value-of select="number(substring(., 8, 2))"/> </xsl:variable> <xsl:variable name="month-abbrev"> <xsl:value-of select="document('data.xml')/data/month-names/month[@sequence = $month]"/> </xsl:variable> <!-- and the output --> <xsl:value-of select="$day"/> <xsl:text>-</xsl:text> <xsl:value-of select="$month-abbrev"/> <xsl:text>-</xsl:text> <xsl:value-of select="$year"/> The document() function makes the document 'data.xml' just another data set to work with. Elizabeth XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Date Formating, Arthur | Thread | Re: [xsl] Date Formating, Perry Molendijk |
Re: [xsl] Date Formating, Heiko Specht | Date | Re: [xsl] Date Formating, Perry Molendijk |
Month |