By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,740 Members | 844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,740 IT Pros & Developers. It's quick & easy.

xsl:processing-instruction name="php"

brettl
P: 41
Hey all.

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
  1. <xsl:template match="f[@n='pubdate']">
  2. <xsl:if test="string-length(current()) &gt; 0">
  3.  
  4. <xsl:processing-instruction name="php">
  5.      $today=time();
  6.     $pubdate="<xsl:value-of select="current()" />";
  7.     $year = substr($pubdate, 0, -16);
  8.     $month = substr($pubdate, 5, -13);
  9.     $day = substr($pubdate, 8, -10 );
  10.     $hour = substr($pubdate, 11, -7 );
  11.     $minute = substr($pubdate, 14 , -4);
  12.     $second = substr($pubdate, 17, -1);
  13.     $newpubdate = mktime($hour, $minute, $second, $month, $day, $year);
  14.     $difference = $today - $newpubdate;
  15.       echo 'Date: ';
  16.       echo floor($difference / 84600);
  17.       $difference -= 84600 * floor($difference / 84600);
  18.       echo ' days, ';
  19.       echo floor($difference / 3600);
  20.       $difference -= 3600 * floor($difference / 3600);
  21.       echo ' hours, ';
  22.       echo floor($difference / 60);
  23.       $difference -= 60 * floor($difference / 60);
  24.       echo ' minutes, and'. $difference.' seconds ago.';
  25.     </xsl:processing-instruction>
  26.  
  27. </xsl:if>
  28. </xsl:template>
  29.  
For some reason I can't get the outputed PHP to run. I get the following page source but the PHP doesn't do anything.


[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
Sep 21 '07 #1
Share this Question
Share on Google+
2 Replies


pbmods
Expert 5K+
P: 5,821
Heya, Brett.

XSL is evaluated client-side by the browser, whereas PHP is evaluated server-side. The only way to evaluate PHP is to load and execute the file on the server.
Sep 21 '07 #2

brettl
P: 41
Doh!

Thanks for the help pbmods.
Sep 22 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.