Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting XML items

Status
Not open for further replies.

relisys

Programmer
Mar 6, 2003
65
GB
I'm loading dates from a MySQL database to an XML DOM.
The time is in format 2003-04-04 (YYYY-MM-DD)

Is there any way i can use XSL to translate t2003-04-04 to "4 April 2003" when it outputs to HTML.

I'd prefer if i could than to get java to convert it then output these times to the DOM.

Cheers!


Relisys

 
Sure, make named template and use function "substring" to find the day, month, year.
To get a text-value for month, you'll have to use <xsl-choose>
So, the part to get the month would be something like:
Code:
<xsl:variable name=&quot;monthnr&quot; select=&quot;substring($date,6,2)&quot;/>
<xsl:choose>
<xsl:when test=&quot;$monthnr='01'&quot;>JAN</xsl:when>
<xsl:when test=&quot;$monthnr='02'&quot;>FEB</xsl:when>
</xsl:choose>
Mind you, I didn't try it, so you'll problably have to clean up a little...
 
Dunno if you still need it, but I had to make the thing latelely. Here goes:
Code:
	<xsl:template name=&quot;dateformat&quot;>
		<xsl:param name=&quot;datestring&quot;/>
		<xsl:variable name=&quot;month&quot;>
			<xsl:value-of select=&quot;substring($datestring,6,2)&quot;/>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test=&quot;substring($datestring,9,1)!='0'&quot;>
				<xsl:value-of select=&quot;substring($datestring,9,1)&quot;/>
			</xsl:when>
		</xsl:choose>
		<xsl:value-of select=&quot;substring($datestring,10,1)&quot;/>
		<xsl:choose>
			<xsl:when test=&quot;$month='01'&quot;> JAN </xsl:when>
			<xsl:when test=&quot;$month='02'&quot;> FEB </xsl:when>
			<xsl:when test=&quot;$month='03'&quot;> MAR </xsl:when>
			<xsl:when test=&quot;$month='04'&quot;> APR </xsl:when>
			<xsl:when test=&quot;$month='05'&quot;> MAY </xsl:when>
			<xsl:when test=&quot;$month='06'&quot;> JUN </xsl:when>
			<xsl:when test=&quot;$month='07'&quot;> JUL </xsl:when>
			<xsl:when test=&quot;$month='08'&quot;> AUG </xsl:when>
			<xsl:when test=&quot;$month='09'&quot;> SEP </xsl:when>
			<xsl:when test=&quot;$month='10'&quot;> OCT </xsl:when>
			<xsl:when test=&quot;$month='11'&quot;> NOV </xsl:when>
			<xsl:when test=&quot;$month='12'&quot;> DEC </xsl:when>
		</xsl:choose>
		<xsl:value-of select=&quot;substring($datestring,1,4)&quot;/>
	</xsl:template>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top