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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatting data

Status
Not open for further replies.

caf

Programmer
Sep 19, 2000
124
ZA
Hi

I need an xsl directive to format a date stored in an xml file as yyyy-mm-ddThh:mm:ss.

Example

2001-12-01T09:02:56

I want to display this date like this
dd/mm/yyyy not showing the time.

Example
01/12/2001

How would I acomplish this without formatting the data before writing the xml file. I'm using the generic format ADO generates when firing the RecordSet.Save event.

I have to use this (generic) format so a custom format is not an option.

I acquire the data
Issue the RecordSet.Save file to get the xml
apply the formatting to the generic xml file via xsl.

Thank you in advance

caf
 
Ok I've solved the problem but I'm still not satisfied. I'm using JScript to format the date passed to a function.

Here's a fragment

Code:
function formatTheDate(varDate) {
	var tempDate = new Date();

	tempDate.setYear(varDate.substr(0,4));
	tempDate.setMonth(varDate.substr(5,2));
	tempDate.setDate(varDate.substr(8,2));

	var formattedDate = temp.getDate();

	formattedDate += "/";
	formattedDate += temp.getMonth();
	formattedDate += "/";
	formattedDate += temp.getYear();

	return(formattedDate);
}

Anybody have any ideas as to a better way to do this?

As you can see I'm working with text passed to the function so my xsl, calling this function looks like this


<xsl:template match=&quot;@*&quot;>
<xsl:choose>
<xsl:when test=&quot;/xml/layout/field[@name $ieq$ context(-2)/@name]/@format[text() $ieq$ 'currency']&quot;>
<xsl:eval >formatTheCurrency(this.text)</xsl:eval>
</xsl:when>
<xsl:when test=&quot;context(-2)/s:datatype/@rs:dbtype[text() $ieq$ 'currency']&quot;>
<xsl:eval >formatTheCurrency(this.text)</xsl:eval>
</xsl:when>
<xsl:when test=&quot;/xml/layout/field[@name $ieq$ context(-2)/@name]/@format[text() $ieq$ 'dateTime']&quot;>
<xsl:eval >formatTheDate(this.text)</xsl:eval>
</xsl:when>
<xsl:when test=&quot;/xml/layout/field[@name $ieq$ context(-2)/@name]/@format[text() $ieq$ 'date']&quot;>
<xsl:eval >formatTheDate(this.text)</xsl:eval>
</xsl:when>
<xsl:when test=&quot;context(-2)/s:datatype/@dt:type[text() $ieq$ 'dateTime']&quot;>
<xsl:eval >formatTheDate(this.text)</xsl:eval>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select=&quot;text()&quot; />
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top