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

XSLT Date formatting problems

Status
Not open for further replies.

damnrad

Programmer
May 8, 2006
2
GB
Hello

How would I format the date to MM DD, YY?... the date is from <xsl:value-of select="pubDate"/>

Currently it's displaying as 2005-09-08 08:15:00.0 which is not validating.

Here is my XSL:

<div>
<xsl:for-each select="channel/item">
<div>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="link"/>
</xsl:attribute>
<xsl:value-of select="title"/>
</xsl:element>
</div>
<div>
<xsl:value-of disable-output-escaping="yes" select="description" />
<br />
<span class="comments">
<xsl:value-of select="pubDate" />
</span>
</div><br />
</xsl:for-each>
</div>


</div>



Any help would be fantastic. Great site by the way.



W

 
Other than using extension functions (such as EXSLT), you'll have to use substring:
Code:
<xsl:value-of select="concat(substring(pubDate, 6, 2), '-', substring(pubDate, 9, 2), '-', substring(pubDate, 3, 2))" />
ps can someone explain the logic behind the american dating of MM DD YY rather than DD MM YY?

Jon

"I don't regret this, but I both rue and lament it.
 
Thanks Jon I appreciate it

That worked for me, but I have now discovered I have formatted it at the wrong level, so I am still getting the same Feed Validator error (pubDate must be an RFC-822 date-time). I need to format it at the xml level inside the <channel> tag.

Do you know if it's poossible to format the xml data?

Below is my xml. It's the variable $issueDate that needs to change.


<item>
<link> <title><![CDATA[$title]]></title>
<pubDate>$issueDate</pubDate>
<description><![CDATA[$intro]]></description>
<guid isPermaLink="true"></item>
 
What is $issueDate?? How do you substitute for actual values?

Jon

"I don't regret this, but I both rue and lament it.
 
Can someone explain the logic behind the american dating of MM DD YY rather than DD MM YY
Logic? Americans? That's a bit of a tall order.

I think it's because they'd tend to say "Today is May the 8th, 2006", so note it down as 5/8/2006. Though maybe they say it that way 'cos they write it that way. Who knows.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Both the US and UK date formats are incorrect for use in XML.

The W3C specifies ISO-8601 format for storing datetime values inside an XML node.

Otherwise, what you have is not a datetime, but a string which resembles a datetime -- in certain parts of the world.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top