Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xls transformation of a external xml page

Status
Not open for further replies.

hame22

Programmer
Apr 25, 2005
9
GB
hi all

is it possible (and if so how) to transform through XSL and PHP an external XML page that is dynamically produced through PHP??

This PHP page that produces XML is based upon a id variable so that its url is like "
also is it possible to do the same to a similar file on my webserver, mypage.php?id=4


thanks in advance

alex
 
I'm not an expert in PHP, I prefer classic PHP or asp.NET, but I've tried to do xml/xsl transformations in as many languages as possible - and PHP seems to about the worst option.

First problem - PHP uses an "add-on" xsl processor called Sablotron, with which you need to compile PHP if you're running your own server. If you're using shared hosting you might find that its there, you might find that it isn't it's worth checking if you're setting up a new account.

Second problem - ASP, JSP, Perl, asp.NET can all create XML objects. PHP can't, so the standard method/hack of pulling a remote XML source seems to be to write a script which writes the XML to a local file, then use Sablotron to read the file.

Try the following code

<?php
$open = fopen(" "r");
$xmlstring = fread($open, 10000);
fclose($open);


$fp = fopen ("./localsource.xml", "w");

fputs ($fp, $xmlstring, strlen($xmlstring));
fclose ($fp);
?>


<?php
$xh = xslt_create();
$result = xslt_process($xh, 'localsource.xml', 'transform.xsl');
if ($result) {
echo $result;
}
else {
echo xslt_error($xh);
}
xslt_free($xh);
?>

You'll probably need to create an empty file called localsource.xml and chmod it to 666.

Sometimes this script works, sometimes it falls over in the middle of writing the remote XML to the local file.

If anyone knows a better method then I'd like to know. Personally I've given up on PHP for this particular task, if I have to transform a remote source on a UNIX platform I use Perl.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top