DCfromDisplay
asked on
Format Date Using XSL
I need to format the date in an XML Response. It is returned in the following format YYYYMMDD, and I'd like to have it display as MM/DD/YYYY.
I have the following code in place in the XSL file, and if I replace
value-of select="ms:format-date(Dat e, 'MMM dd, yyyy')"/
with just Date, I can get the results unformatted, but I'm apparently a bit off on my attempt to format.
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ms="urn:schemas-micr osoft-com: xslt"
xmlns:dt="urn:schemas-micr osoft-com: datatypes" >
<xsl:template match="/">
<html>
<body>
<h2>Tracking Results</h2>
<table width="70%" border="1" cellpadding="1" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#CCCCCC">
<tr>
<th>Date</th>
<th>Time</th>
<th>Location</th>
<th>Activity</th>
</tr>
<xsl:for-each select="TrackResponse/Ship ment/Packa ge/Activit y">
<tr>
<td width="10%"><xsl:value-of select="ms:format-date(Dat e, 'MMM dd, yyyy')"/></td>
<td width="10%"><xsl:value-of select="Time"/></td>
<td width="40%"><xsl:value-of select="ActivityLocation/A ddress/Cit y"/>,
<xsl:value-of select="ActivityLocation/A ddress/Sta teProvince Code"/>,
<xsl:value-of select="ActivityLocation/A ddress/Cou ntryCode"/ ></td>
<td width="40%"><xsl:value-of select="Status/StatusType/ Descriptio n"/></td>
...etc
Hopefully my explanation is clear.
Thanks in advance.
I have the following code in place in the XSL file, and if I replace
value-of select="ms:format-date(Dat
with just Date, I can get the results unformatted, but I'm apparently a bit off on my attempt to format.
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ms="urn:schemas-micr
xmlns:dt="urn:schemas-micr
<xsl:template match="/">
<html>
<body>
<h2>Tracking Results</h2>
<table width="70%" border="1" cellpadding="1" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#CCCCCC">
<tr>
<th>Date</th>
<th>Time</th>
<th>Location</th>
<th>Activity</th>
</tr>
<xsl:for-each select="TrackResponse/Ship
<tr>
<td width="10%"><xsl:value-of select="ms:format-date(Dat
<td width="10%"><xsl:value-of select="Time"/></td>
<td width="40%"><xsl:value-of select="ActivityLocation/A
<xsl:value-of select="ActivityLocation/A
<xsl:value-of select="ActivityLocation/A
<td width="40%"><xsl:value-of select="Status/StatusType/
...etc
Hopefully my explanation is clear.
Thanks in advance.
ASKER
Yeah, it looks like I should get away from using MSXML 4. While I'm not crystal clear on the solution after looking at your example, I hope to figure it out over the weekend.
Thanks again,
Darryl
Thanks again,
Darryl
oh, I meant you need to use MSXML 4, if you want the built-in IXTLRuntime format-date() function. I think it was left out of MSXML 3, but I can't say for sure.
Regards,
Mike Sharp
Regards,
Mike Sharp
ASKER
I'm afraid that I've not been able to make it work using your example. Any other suggestions would be greatly appreciated.
The problem with the MSXML 4 that I see is that I can't be sure that every client that tries to access this page will have these capabilities.
Also, here is a sample of the XML Response that I receive.
<?xml version="1.0" encoding="UTF-8"?>
<TrackResponse>
<Response>
<TransactionReference>
<XpciVersion>1.0001</XpciV ersion>
</TransactionReference>
<ResponseStatusCode>1</Res ponseStatu sCode>
<ResponseStatusDescription >Success</ ResponseSt atusDescri ption>
</Response>
<Shipment>
<Shipper>
<ShipperNumber>12345E</Shi pperNumber >
</Shipper>
<Service>
<Code>15</Code>
<Description>NDA EAM/EXP EAM</Description>
</Service>
<ShipmentIdentificationNum ber>1Z1234 5678998765 4</Shipmen tIdentific ationNumbe r>
<Package>
<TrackingNumber>1Z12345678 9987654</T rackingNum ber>
<Activity>
<ActivityLocation>
<Address>
<City>CLARKVILLE</City>
<StateProvinceCode>AK</Sta teProvince Code>
<PostalCode>99901</PostalC ode>
<CountryCode>US</CountryCo de>
</Address>
<Code>ML</Code>
<Description>FRONT DOOR</Description>
</ActivityLocation>
<Status>
<StatusType>
<Code>D</Code>
<Description>DELIVERED</De scription>
</StatusType>
<StatusCode>
<Code>FS</Code>
</StatusCode>
</Status>
<Date>20031002</Date>
<Time>135500</Time>
</Activity>
The problem with the MSXML 4 that I see is that I can't be sure that every client that tries to access this page will have these capabilities.
Also, here is a sample of the XML Response that I receive.
<?xml version="1.0" encoding="UTF-8"?>
<TrackResponse>
<Response>
<TransactionReference>
<XpciVersion>1.0001</XpciV
</TransactionReference>
<ResponseStatusCode>1</Res
<ResponseStatusDescription
</Response>
<Shipment>
<Shipper>
<ShipperNumber>12345E</Shi
</Shipper>
<Service>
<Code>15</Code>
<Description>NDA EAM/EXP EAM</Description>
</Service>
<ShipmentIdentificationNum
<Package>
<TrackingNumber>1Z12345678
<Activity>
<ActivityLocation>
<Address>
<City>CLARKVILLE</City>
<StateProvinceCode>AK</Sta
<PostalCode>99901</PostalC
<CountryCode>US</CountryCo
</Address>
<Code>ML</Code>
<Description>FRONT DOOR</Description>
</ActivityLocation>
<Status>
<StatusType>
<Code>D</Code>
<Description>DELIVERED</De
</StatusType>
<StatusCode>
<Code>FS</Code>
</StatusCode>
</Status>
<Date>20031002</Date>
<Time>135500</Time>
</Activity>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks again...I think I'm well on my way now.
Darryl
Darryl
If you can't use MSXML 4 to do this, you'll have to resort to MSXML 3, and in that case I usually just write an extension function that does what I need. Here's an example that plays around with dates:
http://dev.rdcpro.com/Members/rdcpro/snippets/filterandsort/
Chris Bayes has written an MSXSL extension that supports EXSLT:
http://www.exslt.org/date/functions/format-date/date.msxsl.xsl
Regards,
Mike Sharp
http://dev.rdcpro.com