I'm not sure if this question should be posted here or in the XML forums. Please forgive me if its in the wrong place or feel free to move it.
Any who, I'm using a SOAP service to display a list of news articles. I'm outputing the results using XSLT.
I'm using the following code to strip the returned pubdate and then calculate the time between today's date and the pubdate.
Expand|Select|Wrap|Line Numbers
- <xsl:template match="f[@n='pubdate']">
- <xsl:if test="string-length(current()) > 0">
- <xsl:processing-instruction name="php">
- $today=time();
- $pubdate="<xsl:value-of select="current()" />";
- $year = substr($pubdate, 0, -16);
- $month = substr($pubdate, 5, -13);
- $day = substr($pubdate, 8, -10 );
- $hour = substr($pubdate, 11, -7 );
- $minute = substr($pubdate, 14 , -4);
- $second = substr($pubdate, 17, -1);
- $newpubdate = mktime($hour, $minute, $second, $month, $day, $year);
- $difference = $today - $newpubdate;
- echo 'Date: ';
- echo floor($difference / 84600);
- $difference -= 84600 * floor($difference / 84600);
- echo ' days, ';
- echo floor($difference / 3600);
- $difference -= 3600 * floor($difference / 3600);
- echo ' hours, ';
- echo floor($difference / 60);
- $difference -= 60 * floor($difference / 60);
- echo ' minutes, and'. $difference.' seconds ago.';
- </xsl:processing-instruction>
- </xsl:if>
- </xsl:template>
[HTML]<div xmlns:php="http://php.net/xsl" class="sectionheadsm">
<h3>News from the Web</h3>
</div><div xmlns:php="http://php.net/xsl" id="news">
<ul>
<li>
<a href="http://www.news.net/id_newsarticle/CA6476653.html" onmousedown="ebatr('710',this.href,'news','news.co m+Creates+Virtual+Carpet+Samples','by+Laura+B.+Wei ss','2007-09-10T00%3A00%3A00Z');">Carpet.com Creates Virtual Carpet Samples</a>
<br/>
<div class="publication">
Source: News</div>
<div class="date">
<?php
$today=time();
$pubdate="2007-09-10T00:00:00Z";
$year = substr($pubdate, 0, -16);
$month = substr($pubdate, 5, -13);
$day = substr($pubdate, 8, -10 );
$hour = substr($pubdate, 11, -7 );
$minute = substr($pubdate, 14 , -4);
$second = substr($pubdate, 17, -1);
$newpubdate = mktime($hour, $minute, $second, $month, $day, $year);
$difference = $today - $newpubdate;
echo 'Date: ';
echo floor($difference / 84600);
$difference -= 84600 * floor($difference / 84600);
echo ' days, ';
echo floor($difference / 3600);
$difference -= 3600 * floor($difference / 3600);
echo ' hours, ';
echo floor($difference / 60);
$difference -= 60 * floor($difference / 60);
echo ' minutes, and'. $difference.' seconds ago.';
?>
</div>
</li>
</ul>
</div>
</div>[/HTML]
Any help with this would be greatly appreciated.
Thanks