Re: [xsl] splitting the date field in xml

Subject: Re: [xsl] splitting the date field in xml
From: jim smith <jim@xxxxxxxxx>
Date: Wed, 14 Feb 2001 00:44:36 +0000
Hi

I have a xml file which looks like this

<Context>
	<Date>Tue Jan 11 16:00:00 PST 1949</Date>
</Context>

I need to show the date in 3 textfields as

Jan 11 1949



Obviously with...

<satire>

<xsl:script implements="really-obvious-regex-things-XSLT-pretends-it-doesn't-need" language="perl">

</satire>

More seriously:

I've cheated a bit and made two assumptions:

1. that the length of the day of the month field never changes
2. that the length of the of the time field never changes

You can probably fix it if only one of those changes with a string-length() - eg if the string is less than 28 characters you know you're dealing with a shortened date or time and can wrap it in an xsl:when

If both change - eg, if you don't pad date and time with leading zeroes, then i'm baffled.

I also cheated and pinched the padding spaces from the string itself.

<?xml version="1.0"?>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="Context">

<xsl:value-of select="substring(Date, 5, 4)" /><xsl:value-of select="substring(Date, 9, 3)" /> <xsl:value-of select="substring(Date, 25, 4)" />

	</xsl:template>
</xsl:stylesheet>
--



jim smith
020 7837 0377

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


Current Thread