Jump to content

Recommended Posts

I cannot get the following XSLT to work. I am grabbing the feed properly but the HTML and the XML elements that are supposed to fill it are not being displayed at all. Can some one please help / debug my code? Code follows below.

 

I have the following code that successfully grabs an XML feed:

<?php
$detailsObtained = false;
$syms = "";
$serviceURL = "http://localhost:8880/detailed_quote.html.xml";
$cobj=curl_init($serviceURL);
curl_setopt($cobj,CURLOPT_RETURNTRANSFER,1);
$response=curl_exec($cobj);
curl_close($cobj);

if ($response)
{
     $detailsObtained = true;
}
else echo "Error reading feed";

if ($detailsObtained)
{
   $parser = xslt_create();
   $html = xslt_process($parser,$response,"/var/www/html/transform.xsl");
   echo($html);
}
?>

 

My XSL looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <h2>Stocks</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th align="left">Ticker</th>
        <th align="left">high</th>
      </tr>
      <xsl:for-each select="MSXML/quote">
      <tr>
        <td><xsl:value-of select="ticker" /></td>
        <td><xsl:value-of select="high" /></td>
      </tr>
      </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

 

And the abbreviated XML feed (which I cannot change the format of) and will have to stay as is looks like the following:

<MSXML>
        <quote source="MSFT">
                        <ticker>MSFT</ticker>
                                <description>MICROSOFT CORP.</description>
                                <current>28.54</current>
                                <netChange>+0.10</netChange>
                                <percentChange>+0.35%</percentChange>
                                <open>28.67</open>
                                <high>28.75</high>
                                <low>28.41</low>
                                <close>28.44</close>
                                <oneYearHigh>31.84</oneYearHigh>
                                <oneYearLow>25.42</oneYearLow>
                                <dateTime>09/10/2007 14:14 EDT</dateTime>
                </quote>
                <quote source="SPX.X">
                               <ticker>SPX.X</ticker>
.
.
.
</MSXML>

Link to comment
https://forums.phpfreaks.com/topic/68787-need-help-with-an-xslt/
Share on other sites

Another way is to create a "data island"

 

<xml src="tktquote.xml" id="quote" async="false">
</xml>

<table datasrc="#quote" width="50%" border="1">
<thead>
<th>Description</th>
<th>High</th>
</thead>

<tr align="left">
<td><div datafld="description"></div></td>
<td><div datafld="high"></div></td>
</tr>

</table>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.