xsl:processing-instruction name="php"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brettl
    New Member
    • Sep 2007
    • 41

    xsl:processing-instruction name="php"

    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.

    [CODE=xml]
    <xsl:template match="f[@n='pubdate']">
    <xsl:if test="string-length(current( )) &gt; 0">

    <xsl:processi ng-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($differen ce / 84600);
    $difference -= 84600 * floor($differen ce / 84600);
    echo ' days, ';
    echo floor($differen ce / 3600);
    $difference -= 3600 * floor($differen ce / 3600);
    echo ' hours, ';
    echo floor($differen ce / 60);
    $difference -= 60 * floor($differen ce / 60);
    echo ' minutes, and'. $difference.' seconds ago.';
    </xsl:processing-instruction>

    </xsl:if>
    </xsl:template>
    [/CODE]

    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="sectionh eadsm">
    <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="eb atr('710',this. href,'news','ne ws.com+Creates+ Virtual+Carpet+ Samples','by+La ura+B.+Weiss',' 2007-09-10T00%3A00%3A00 Z');">Carpet.co m Creates Virtual Carpet Samples</a>
    <br/>
    <div class="publicat ion">

    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($differen ce / 84600);
    $difference -= 84600 * floor($differen ce / 84600);
    echo ' days, ';
    echo floor($differen ce / 3600);
    $difference -= 3600 * floor($differen ce / 3600);
    echo ' hours, ';
    echo floor($differen ce / 60);
    $difference -= 60 * floor($differen ce / 60);
    echo ' minutes, and'. $difference.' seconds ago.';
    ?>
    </div>
    </li>
    </ul>
    </div>
    </div>[/HTML]



    Any help with this would be greatly appreciated.

    Thanks
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    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.

    Comment

    • brettl
      New Member
      • Sep 2007
      • 41

      #3
      Doh!

      Thanks for the help pbmods.

      Comment

      Working...