XML to HTML

Associate
Joined
28 Mar 2004
Posts
604
Location
Devon, UK
Ok,

I'm hoping there are some clever sods in here that can help me with a php script I have for converting an xml feed into HTML.

I grabbed it from a website I use which displayed the member list and modified it to show more details from another feed. I now have it displaying the fields I want but I need to break the display up and I'm assuming it's because it's using the single parameter still

Code:
<?php
$mblist = '';
$flag = false;

function openElement($parser, $element, $attributes) {
global $flag;
if ($element == 'pilot') $flag = true;
if ($element == 'aircraft') $flag = true;
if ($element == 'from') $flag = true;
if ($element == 'to') $flag = true;
if ($element == 'income') $flag = true;

}

function closeElement($parser, $element) {
global $flag;
$flag = false;
}

function characterData($parser, $data) {
global $flag,$mblist;
if ($flag) $mblist[] = $data;
}



// Create an XML parser
$parser = xml_parser_create();

xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($parser, "openElement", "closeElement");
xml_set_character_data_handler($parser, "characterData");

// Open the XML file for reading, change path for your Data
$document = file_get_contents("http://atilla.hinttech.nl:8080/fseconomy/xml?id=5186&key=IYASV3D7&query=groupLog&from=5&amount=10","r")
or die("Error reading XML data.");


xml_parse($parser, $document);

xml_parser_free($parser);

echo '<table border=1>';
echo '<tr><td><b>User Name</b></td></tr>';


foreach ($mblist as $value) {
echo '<tr><td>';
echo $value;
echo '</td></tr>';
}
echo '</table>';

?>

This is the display http://www.simpilots.co.uk/testfeed.php

Basically the feed is showing a username, followed by an aircraft name, 2 departure and arrival airport and income earned. Then need to seperate after that and put a $ sign in for the income.

Can someone help please?
 
Sorry not completely useful at this kind of thing, hence trying to mod an exisiting script.

How would I go about using XLST?
 
ok just looking at these options. I'm assuming to use XLST, I need to link the stylesheet to the XML source file? In which case I can't do this as the XML file is on another server. Also, am I right in thinking that for simpilexml to work, I need to install something on my host server?

I've got this working so which is ok, would just like to be able to center the entries, but again can't find the line to do it.

PHP:
<?php
$mblist = '';
$flag = false;

function openElement($parser, $element, $attributes) {
global $flag;
if ($element == 'pilot') $flag = true;
if ($element == 'aircraft') $flag = true;
if ($element == 'from') $flag = true;
if ($element == 'to') $flag = true;
if ($element == 'income') $flag = true;

}

function closeElement($parser, $element) {
global $flag;
$flag = false;
}

function characterData($parser, $data) {
global $flag,$mblist;
if ($flag) $mblist[] = $data;
}



// Create an XML parser
$parser = xml_parser_create();

xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($parser, "openElement", "closeElement");
xml_set_character_data_handler($parser, "characterData");

// Open the XML file for reading, change path for your Data
$document = file_get_contents("http://atilla.hinttech.nl:8080/fseconomy/xml?id=5186&key=IYASV3D7&query=groupLog&from=5&amount=10","r")
or die("Error reading XML data.");


xml_parse($parser, $document);

xml_parser_free($parser);

echo '<table border=0>';
echo '<div align="center"><tr><td><b>User Name</b></td><td><b>Aircraft Reg</b></td><td><b>Departure</b></td><td><b>Arrival</b></td><td><b>Money Earned ($)</b></td></tr></div>';


$x=0;
foreach ($mblist as $value) {
$x=$x+1;
if ($x==1) echo '<tr>';
echo '<td>';
echo $value;
echo '</td>';
if ($x==5) {
echo '</tr>';
$x=0;
}
}
echo '</table>'; 

?>
 
Well have it filtered to 10 now and displays well

http://www.simpilots.co.uk/index.php?option=com_content&task=view&id=28&Itemid=33

but..........I would like to be able to filter it on username.

We have about 6 users at the moment and would like to add a list of their names and then when you click on their name, it filters out on them.

My XSL file looks like this

Code:
<?xml version="1.0" encoding="utf-8"?><!-- DWXMLSource="http://atilla.hinttech.nl:8080/fseconomy/xml?id=5186&key=IYASV3D7&query=groupLog" --><!DOCTYPE xsl:stylesheet  [
	<!ENTITY nbsp   " ">
	<!ENTITY copy   "©">
	<!ENTITY reg    "®">
	<!ENTITY trade  "™">
	<!ENTITY mdash  "—">
	<!ENTITY ldquo  "“">
	<!ENTITY rdquo  "”"> 
	<!ENTITY pound  "£">
	<!ENTITY yen    "¥">
	<!ENTITY euro   "€">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8"/>
<xsl:template match="/"><style type="text/css">
<xsl:comment>
</xsl:comment>
</style><link href="templates/js_lunar_eclipse/css/template_css.css" rel="stylesheet" type="text/css" /><style type="text/css">
<xsl:comment>
</xsl:comment>
      </style>
      
      
      


<p align="left"></p>
<div align="left">
  <table width="800" border="1" align="center">
    <tr>
      <td><div align="center"><strong>Pilot Name</strong></div></td>
        <td><div align="center"><strong>Aircraft Registration</strong></div></td>
        <td><div align="center"><strong>Departure Airport</strong></div></td>
        <td><div align="center"><strong>Arrival Airport</strong></div></td>
        <td><div align="center"><strong>Rental Cost ($)</strong></div></td>
        <td><div align="center"><strong>Landing Cost ($)</strong></div></td>
        <td><div align="center"><strong>Fuel Cost</strong> <strong>($)</strong></div></td>
        <td><div align="center"><strong>Income ($)</strong></div></td>
      </tr>
  <xsl:for-each select="response/groupLog/@id[. &lt; 10]">
      <tr>
        <td height="10"><div align="center">
          <p><xsl:value-of select="../pilot"/></p>
          </div></td>
        <td height="10"><div align="center">
          <p><xsl:value-of select="../aircraft"/></p>
            </div></td>
        <td height="10"><div align="center">
          <p><xsl:value-of select="../from"/></p>
            </div></td>
        <td height="10"><div align="center">
          <p><xsl:value-of select="../to"/></p>
            </div></td>
        <td><div align="center"><xsl:value-of select="../rentalCost"/></div></td>
        <td><div align="center"><xsl:value-of select="../landingCost"/></div></td>
        <td><div align="center"><xsl:value-of select="../fuelCost"/></div></td>
        <td height="10"><div align="center">
          <p><xsl:value-of select="../income"/></p>
            </div></td>
      </tr>
    </xsl:for-each>
  </table>
</div>
<p align="left"></p>
<p align="left"></p>
</xsl:template>
</xsl:stylesheet>

I was thinking that I need to enter 'if' blocks and then returning different repeating regions, filtering on the username, but again, unsure how
 
Back
Top Bottom