Sorry, I have no better forum to file this under.

Here is my issue. I'm working on a non-profit theater site who uses a third party box office solution for selling tickets in house and on the web. This service publishes showtimes on HTML pages transformed from XML. They will not allow us to style these HTML pages so we will have to make our own XSL transformations, something I know next to nothing about. Since this service they use developed it process at a time before there were such a thing as XML standards and have flat out refused to update their method, all the example XSLT scripts just plain don't work. So, I am approaching the only community I have an 'in' with to help me figure out what I need to do.

It doesn't seem like there is a functional XML import module for Drupal, even though some people have started projects on it. I am not sure we want to create nodes for each showtime either. In the end, I need to create seven HTML files to SSI into drupal nodes for each day of the week. I don't know all of the date formatting and sorting vocabulary but I'll cross that once I get there.

I found this code that works just great in a practice environment with dummy files:


// Allocate a new XSLT processor
$xh = xslt_create();

// Process the document
if (xslt_process($xh, 'aa_showtimes.xml', 'aa_format.xsl' , 'result.html')) {
    print "SUCCESS, sample.xml was transformed by sample.xsl into result.xml";
    print ", result.xml has the following contents\n<br>\n";
    print "\n&quot;;&#10;    readfile(&#039;result.html&#039;);&#10;    print &quot;\n";
}
else {
    print "Sorry, sample.xml could not be transformed by sample.xsl into";
    print "  result.xml the reason is that " . xslt_error($xh) . " and the ";
    print "error code is " . xslt_errno($xh);
}

xslt_free($xh);

It's all fine and dandy but the XML data is a web link, not a file, and I'm not even sure if its well-formed. In my back asswards understanding, I tried to swap the aa_showtimes.xml file with the link to their XML data:

http://www.readyticket.net/webticket/webticket2.asp?WCI=getxmlshowtimes&...

Needless to say it seems to break, either because of my poor understanding or because of their bad XML. The error message I get here is, "Warning: Sablotron error on line 1: XML parser error 4: not well-formed in /home/schottfe/public_html/aa_process.php on line 7".

I found a comment on another board that suggests how to override the poorly formed data:

http://us3.php.net/manual/en/ref.xsl.php

But I can't make that example work either.

Do any of you PHP speaking geniuses have a tip or two for me? I would also love to find another online community that more specializes in PHP specific coding, I know most of the commentary on drupal.org is related specifically to drupal.

Comments

styro’s picture

XSL on random non semantic HTML is doomed to failure, unless you can convert it to valid XHTML.

You might want to look into HTMLTidy to hopefully tidy up the HTML and do the conversion for you.

--
Anton
New to Drupal? | Forum posting tips | Troubleshooting FAQ
Example Knowledge Base built using Drupal

nevets’s picture

Subject says it all. By the way though, try pointing firefox at the link, you can view it then.

somes’s picture

I’m no XSLT guru or XML pro so this could all be rubbish

I had a similar problem a month or so back and I ended up going with using a curl library to retrieve xml data from an external source

function HTTPRequest($url){ 
      $ch = curl_init(); 
      curl_setopt($ch,CURLOPT_URL,$url); 
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
      curl_setopt($ch,CURLOPT_MUTE,1); 
      curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]); 
      curl_setopt($ch, CURLOPT_TIMEOUT, 10); //times out after 10 
      curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); 
      $data = curl_exec ($ch); 
      curl_close ($ch); 
      return $data; 
   }

and calling the function with

$xmlID = HTTPRequest("http://www.mysite.com/search.cgi?db=*****");

this may not help you as you are also trying to use SSI but it might give you some ideas

what does the xml file look like – are the tags the fields of interest or is the data in attribute fields inside the tags

seaneffel’s picture

You will have to excuse my ignorance about PHP, but how do I put these two pieces of code together with the sample XSLT script I worked out above? Would it look like this? I'm just taking a stab in the dark based on my scripting knowledge from FileMaker!


function HTTPRequest($url){ 
      $ch = curl_init(); 
      curl_setopt($ch,CURLOPT_URL,$url); 
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
      curl_setopt($ch,CURLOPT_MUTE,1); 
      curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]); 
      curl_setopt($ch, CURLOPT_TIMEOUT, 10); //times out after 10 
      curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); 
      $data = curl_exec ($ch); 
      curl_close ($ch); 
      return $data; 
  }

$xmlID = HTTPRequest("http://www.mysite.com/myxmldatafileofchoice");

// Allocate a new XSLT processor
$xh = xslt_create();

// Process the document
if (xslt_process($xh, $xmlID, 'aa_format.xsl' , 'result.html')) {
    print "SUCCESS, sample.xml was transformed by sample.xsl into result.xml";
    print ", result.xml has the following contents\n<br>\n";
    print "\n&quot;;&#10;    readfile(&#039;result.html&#039;);&#10;    print &quot;\n";
}
else {
    print "Sorry, sample.xml could not be transformed by sample.xsl into";
    print "  result.xml the reason is that " . xslt_error($xh) . " and the ";
    print "error code is " . xslt_errno($xh);
}

xslt_free($xh);

seaneffel’s picture

If you want to see the error on this one:
http://www.coolidge.org/drupal/aa_process2.php

It says:

Warning: Sablotron error on line 1: XML parser error 4: not well-formed (invalid token) in /home/coolidge/drupal/aa_process3.php on line 22
Sorry, sample.xml could not be transformed by sample.xsl into result.xml the reason is that XML parser error 4: not well-formed (invalid token) and the error code is 2

somes’s picture

Sorry just saw the rest of this try - create a page and put every thing below in - enable php

function HTTPRequest($url){ 
      $ch = curl_init(); 
      curl_setopt($ch,CURLOPT_URL,$url); 
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
      curl_setopt($ch,CURLOPT_MUTE,1); 
      curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]); 
      curl_setopt($ch, CURLOPT_TIMEOUT, 10); //times out after 10 
      curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); 
      $data = curl_exec ($ch); 
      curl_close ($ch); 
      return $data; 
  } 

$xmlDATA = HTTPRequest("http://www.mysite.com/myxmldatafileofchoice");



$arguments = array('/_xml' => $xmlDATA);
   $xsltproc = xslt_create();
   xslt_set_encoding($xsltproc, 'ISO-8859-1');
$html =
       xslt_process($xsltproc, 'arg:/_xml', "pubtransform.xslt", NULL, $arguments);

   if (empty($html)) {
       die('XSLT processing error: '. xslt_error($xsltproc));
   }
   xslt_free($xsltproc);
print($html);

seaneffel’s picture

This is the answer to all my questions. Thanks so much for helping me sor this out, I couldn't have done it on my own. I placed this code into a node, bookended with the right HTML, and it displays the data just like I needed it.

Now all I need is a good resource for writing XSL templates, especially dealing with date functions.

Thanks again!

seaneffel’s picture

I've tried using this link to the XML data too. Even though I get the same errors I believe it is more direct:

http://www.readyticket.net/webticket/htmlshowtimes/130/showtimes.xml

somes’s picture

Sorry I havent looked at your code but what error are you getting

I tried

  // Create a DomDocument object from an xml file. 
  if( !$domXmlObj = domxml_open_file( "http://www.readyticket.net/webticket/htmlshowtimes/130/showtimes.xml" ) ) { 
    die( "Cannot parse the xml file." ); 
  } 

  // Create a DomDocument object from the xslt file. 
  $domXsltObj = domxml_xslt_stylesheet_file( "xsltransform.xslt" ); 
   
  // Create a DomDocument object from the xslt transformation 
  // of the xml and xslt file. 
  $domTranObj = $domXsltObj->process( $domXmlObj ); 
   
  // Display the output of the DomDocument object 
  // from the xslt transformation. 
  echo $domXsltObj->result_dump_mem( $domTranObj ); 

And i get a display of your data

seaneffel’s picture

When I try yoru code I get this error. Use http://www.coolidge.org/drupal/aa_process4.php

"Parse error: syntax error, unexpected T_STRING in /home/coolidge/drupal/aa_process4.php on line 4"

Maybe there is something not config right on our server?
http://www.coolidge.org/drupal/aa_phpinfo.php

somes’s picture

Strange that should work T_STRING might be a snytax error - I would guess that if the xml object wasnt install then it would reply with function not found

try removing all white space in line 4 (where the xml file is being called)

seaneffel’s picture

Whitespace may have been an issue, I deleted everything I could and now I have a different error. Bummer. I just don't understand enough PHP to do this myself.

http://www.coolidge.org/drupal/aa_process4.php

somes’s picture

Yeh that error looks familar and i think thats how i ended up using the httpRequest though it does seem strange that i can get it working on my system
if you google the error you get somthing like

http://www.codecomments.com/archive227-2005-7-529092.html
but I've got no idea whats going on in changing the settings (risky)

check your php info down near the botton it should tell you what xml support the server has

seaneffel’s picture

When you say you have it working on your system does that mean when you run the script off the link in this thread it works, or does it mean you have a similar script running on another server? If it is the latter, can you link it for me?

seaneffel’s picture

msomers, the code you posted did wonders for me. But this freaky thing happens and I can't figure it out. When I create a node as an admin, making sure that there are all the correct privileges and stuff, and using the code below - ONLY the admin account can see the output. Other anonymous and registered users can't see anything but the headline, even the HTML above and below the script are invisible. Log back into admin, and there it is? What am i missing?

To see it (or rather, not see it) go to: http://www.coolidge.org/drupal/showtimes

function HTTPRequest($url){ 
      $ch = curl_init(); 
      curl_setopt($ch,CURLOPT_URL,$url); 
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
      curl_setopt($ch,CURLOPT_MUTE,1); 
      curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]); 
      curl_setopt($ch, CURLOPT_TIMEOUT, 10); //times out after 10 
      curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); 
      $data = curl_exec ($ch); 
      curl_close ($ch); 
      return $data; 
  }
$xmlDATA = HTTPRequest("http://www.readyticket.net/webticket/htmlshowtimes/130/showtimes.xml");

$arguments = array('/_xml' => $xmlDATA);
  $xsltproc = xslt_create();
  xslt_set_encoding($xsltproc, 'ISO-8859-1');
$html =
      xslt_process($xsltproc, 'arg:/_xml', "aa_format.xsl", NULL, $arguments);

  if (empty($html)) {
      die('XSLT processing error: '. xslt_error($xsltproc));
  }
  xslt_free($xsltproc);
print($html);
somes’s picture

When you say you create a node are you meaning creating a single page

Try taking the code out and doing a hello world

echo('Hello World');

if that works it a problem with the code

make sure that php code is switched on instead of using filtered or full html
hope that makes sense

seaneffel’s picture

I realized that this problem is actually site wide, not just with this PHP page. Logged in as admin I see pages as they are supposed to appear. If I am logged out, or logged in as an average user, then I see only the title of each node, but no body. The theme and blocks all appear as normal either way.

seaneffel’s picture

This is the solution we found, this was posted in the middle of this thread, just wanted to stamp it at the bottom for anyone looking for the same answer. Thanks to all for the help.

function HTTPRequest($url){ 
      $ch = curl_init(); 
      curl_setopt($ch,CURLOPT_URL,$url); 
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
      curl_setopt($ch,CURLOPT_MUTE,1); 
      curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]); 
      curl_setopt($ch, CURLOPT_TIMEOUT, 10); //times out after 10 
      curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); 
      $data = curl_exec ($ch); 
      curl_close ($ch); 
      return $data; 
  }
$xmlDATA = HTTPRequest("http://www.mysite.com/myxmldatafileofchoice");

$arguments = array('/_xml' => $xmlDATA);
  $xsltproc = xslt_create();
  xslt_set_encoding($xsltproc, 'ISO-8859-1');
$html =
      xslt_process($xsltproc, 'arg:/_xml', "pubtransform.xslt", NULL, $arguments);

  if (empty($html)) {
      die('XSLT processing error: '. xslt_error($xsltproc));
  }
  xslt_free($xsltproc);
print($html);
mskristinahall’s picture

Hello.

Let me explain why I am posting here for help...

I am making a World of Warcraft guild website and one of the things the guild needs is an always up to date guild roster. I want to use the information shown here http://www.wowarmory.com/guild-info.xml?r=Boulderfist&n=Forsaken+Deity&p=1 which when you view the source you can see it is XML, and show a similar listing customized to my liking on my guilds site.

Now I entered the code above into a page, and set it to accept PHP as input and whatnot...

I changed the URL in the line of code below to the link that I think I should be using to pull XML... the code looks like what is below.

<?php
function HTTPRequest($url){
      $ch = curl_init();
      curl_setopt($ch,CURLOPT_URL,$url);
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
      curl_setopt($ch,CURLOPT_MUTE,1);
      curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]);
      curl_setopt($ch, CURLOPT_TIMEOUT, 10); //times out after 10
      curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
      $data = curl_exec ($ch);
      curl_close ($ch);
      return $data;
  }
$xmlDATA = HTTPRequest("http://www.wowarmory.com/guild-info.xml?r=Boulderfist&n=Forsaken+Deity&p=1");

$arguments = array('/_xml' => $xmlDATA);
  $xsltproc = xslt_create();
  xslt_set_encoding($xsltproc, 'ISO-8859-1');
$html =
      xslt_process($xsltproc, 'arg:/_xml', "pubtransform.xslt", NULL, $arguments);

  if (empty($html)) {
      die('XSLT processing error: '. xslt_error($xsltproc));
  }
  xslt_free($xsltproc);
print($html);
?>

After pressing submit, I get the error below... The page won't even create...

Fatal error: Call to undefined function xslt_create() in /home/forsake2/public_html/test/drupal-5.3/includes/common.inc(1347) : eval()'d code on line 17

Can anyone help me sort out how to do this?

nevets’s picture

Are you using PHP 4.* or 5.*? And have you checked that your PHP has the XSLT extension builtin?

mskristinahall’s picture

I'm using hostmonster for my hosting which uses PHP version 5.1.6. I am going to have to contact them to verify about the XSLT extension as nothing is coming up when I do a search on their helpdesk page. :(

Now in the event it doesn't have it... is there another way to get the XML info from the other site?

mskristinahall’s picture

Hi.

I just added XSLT to my PHP and from what tech support has hold me, it should activate the extension...

mskristinahall’s picture

Hi.

XSLT is installed on their server.

mskristinahall’s picture

Now... it lets me hit submit, and then when I try to view the new page I created it gives me the error below


Fatal error: Call to undefined function xslt_create() in /home/forsake2/public_html/test/drupal-5.3/includes/common.inc(1347) : eval()'d code on line 17

And the code entered into the create content > page is:

<?php
function HTTPRequest($url){
      $ch = curl_init();
      curl_setopt($ch,CURLOPT_URL,$url);
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
      curl_setopt($ch,CURLOPT_MUTE,1);
      curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]);
      curl_setopt($ch, CURLOPT_TIMEOUT, 10); //times out after 10
      curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
      $data = curl_exec ($ch);
      curl_close ($ch);
      return $data;
  }
$xmlDATA = HTTPRequest("http://www.wowarmory.com/guild-info.xml?r=Boulderfist&n=Forsaken+Deity&p=1");

$arguments = array('/_xml' => $xmlDATA);
  $xsltproc = xslt_create();
  xslt_set_encoding($xsltproc, 'ISO-8859-1');
$html =
      xslt_process($xsltproc, 'arg:/_xml', "pubtransform.xslt", NULL, $arguments);

  if (empty($html)) {
      die('XSLT processing error: '. xslt_error($xsltproc));
  }
  xslt_free($xsltproc);
print($html);
?>
nevets’s picture

PHP 5 uses a different lextenstion than PHP 4 for this. PHP 5 uses the XSL extension.

mskristinahall’s picture

I found this on the w3schools site... I'm wondering if this is going in the right direction. According to w3schools... "This example is a cross-browser example that loads an existing XML document ("note.xml") into the XML parser." (http://www.w3schools.com/xml/xml_parser.asp)

Would the example below be the right idea?... I have no idea. I'm kinda hoping you'd have an idea...

FYI... my msn is ms [dot] kristina [dot] hall [at] gmail [dot] com . I would really appreciate speaking with you directly about this. Maybe we could work together and come up with a module for future WOW guilds...

<html>
<head>
<script type="text/javascript">
var xmlDoc;
function loadXML()
{
//load xml file
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("note.xml");
getmessage();
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load("note.xml");
xmlDoc.onload=getmessage;
}
else
{
alert('Your browser cannot handle this script');
}
}

function getmessage()
{
document.getElementById("to").innerHTML=xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
document.getElementById("from").innerHTML=xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
document.getElementById("message").innerHTML=xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
}
</script>
</head>

<body onload="loadXML()">
<h1>W3Schools Internal Note</h1>
<p><b>To:</b> <span id="to"></span><br />
<b>From:</b> <span id="from"></span><br />
<b>Message:</b> <span id="message"></span>
</p>
</body>
</html>
styro’s picture

You've gone from trying to use XSLT to transform XML using PHP for use inside Drupal (which is what I assume you want to actually do), to just parsing some XML in the browser using Javascript (which is what I assume you don't want to do).

Try building on the examples here:
http://us.php.net/manual/en/function.xsl-xsltprocessor-construct.php

You will need XSL enabled in your PHP though - try this code to test that:

http://us.php.net/manual/en/function.xsl-xsltprocessor-has-exslt-support...

--
Anton
New to Drupal? | Troubleshooting FAQ
Example knowledge base built with Drupal

mskristinahall’s picture

I'm doing my best to hack this on the very little knowledge I have. :( I hate not knowing enough but I truly do wish to succeed in doing what my guild wants and needs. Hopefully I'm a few steps closer this time....

FYI my MSN is ms [dot] kristina [dot] hall [at] gmail [dot] com ... I would really appreciate speaking with someone knowledgable directly.

ON PAGE IN DRUPAL

<?php

// Load the XML source
$xml = new DOMDocument;
$xml->load('collection.xml');
xml-stylesheet type="text/xsl" href="guildss.xsl";
xmlDoc.selectNodes(//guildKey[@name='Forsaken Deity'])

$xsl = new DOMDocument;
$xsl->load('http://www.wowarmory.com/guild-info.xml');




// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules


echo trim($proc->transformToDoc($xml)->firstChild->wholeText);


?>

EXAMPLE XML from http://www.wowarmory.com/guild-info.xml?r=Boulderfist&n=Forsaken+Deity&p=1 as I cannot view the XML directly from http://www.wowarmory.com/guild-info.xml

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/layout/guild-info.xsl"?><page globalSearch="1" lang="en_gb" requestUrl="/guild-info.xml">
  <guildKey factionId="1" name="Forsaken Deity" nameUrl="Forsaken+Deity" realm="Boulderfist" realmUrl="Boulderfist" url="r=Boulderfist&amp;n=Forsaken+Deity"/>
  <guildInfo>
    <guild>
      <members filterField="" filterValue="" maxPage="1" memberCount="172" page="1" sortDir="a" sortField="">
        <character class="Druid" classId="11" gender="Male" genderId="0" level="70" name="Obsydien" race="Tauren" raceId="6" rank="0" url="r=Boulderfist&amp;n=Obsydien"/>
        <character class="Shaman" classId="7" gender="Female" genderId="1" level="70" name="Daingea" race="Troll" raceId="8" rank="1" url="r=Boulderfist&amp;n=Daingea"/>
        <character class="Druid" classId="11" gender="Male" genderId="0" level="70" name="Maximoo" race="Tauren" raceId="6" rank="2" url="r=Boulderfist&amp;n=Maximoo"/>
...
...
...
      </members>
    </guild>
  </guildInfo>
</page>

XSL STYLESHEET

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  
   <table border="1">
    <tr bgcolor="#000000">
      <th align="left">Name</th>
      <th align="left">Race</th>
      <th align="left">Class</th>
      <th align="left">Level</th>
      <th align="left">Rank</th>
    </tr>
    <xsl:for-each select="guildInfo/guild/members/character">
    <tr>
      <td><a href=" link to detailed char info somehow"><xsl:value-of select="name"/></a></td>
      <td><xsl:value-of select="race"/></td>
      <td><xsl:value-of select="class"/></td>
      <td><xsl:value-of select="level"/></td>
      <td><xsl:value-of select="rank"/></td>
    </tr>
    </xsl:for-each>
    </table>

</xsl:template>

</xsl:stylesheet>
styro’s picture

so I'm just guessing, but there were a few things that occurred to me:

First of all - what did your code do? what errors did you get? did that check for the XSL extension work?

Looking through your code, I'll use PHP comments for questions/pointers:

<?php

$xml = new DOMDocument;
$xml->load('collection.xml');

// what is collection.xml? do you actually want to load it? if so the path correct?


// this line doesn't look like valid PHP
xml-stylesheet type="text/xsl" href="guildss.xsl";


// a) where does xmlDoc come from?
// b) .selectNodes looks more like .NET than PHP
// c) even if this was some hypothetical PHP function, you'd probably want the
//     XPath expression string wrapped in quotes
xmlDoc.selectNodes(//guildKey[@name='Forsaken Deity'])



$xsl = new DOMDocument;

// you'd need to use a working url for this bit
$xsl->load('http://www.wowarmory.com/guild-info.xml');




$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules


// not sure what you are trying to do here
// surely now that you've transformed the data to an HTML table,
// you'd just want to echo that output?
// ie use:
// echo $proc->transformToXML($xml);
echo trim($proc->transformToDoc($xml)->firstChild->wholeText);

// even so it looks like you're loading your XML data (guild-info.xml)
// into the XSL processor rather than the XSLT file (guildss.xsl).
// And then trying to transform collection.xml rather than your data.


?>

--
Anton
New to Drupal? | Troubleshooting FAQ
Example knowledge base built with Drupal

mskristinahall’s picture

Thank you so much for your time and comments. I didn't run the code, in fact it was more hypothetical... as, I'm not very familiar with XML, XSL, XSLT, etc... More of a designer trying to get something to do what I want it to do... if you know what I mean.

I did my best to heed your advice and wrote up some code to enter into a drupal node, as well as uploaded the xsl file I created to my server.

This is the code in the node:

<?php

$xml = new DOMDocument;
$xml->load('http://www.wowarmory.com/guild-info.xml?r=Boulderfist&n=Forsaken+Deity&p=1');

$xsl = new DOMDocument;

$xsl->load('guildss.xsl');

$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); 

echo $proc->transformToXML($xml);

?>

This is the XSL file:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  
   <table border="1">
    <tr bgcolor="#000000">
      <th align="left">Name</th>
      <th align="left">Race</th>
      <th align="left">Class</th>
      <th align="left">Level</th>
      <th align="left">Rank</th>
    </tr>
    <xsl:for-each select="guildInfo/guild/members/character">
    <tr>
      <td><xsl:value-of select="name"/></td>
      <td><xsl:value-of select="race"/></td>
      <td><xsl:value-of select="class"/></td>
      <td><xsl:value-of select="level"/></td>
      <td><xsl:value-of select="rank"/></td>
    </tr>
    </xsl:for-each>
    </table>

</xsl:template>

</xsl:stylesheet>

Below are the errors I am getting when attempting to view the node:



    * warning: DOMDocument::load() [function.DOMDocument-load]: ParsePI: PI xml-stylesheet never end ... in http://www.wowarmory.com/guild-info.xml?r=Boulderfist&n=Forsaken+Deity&p=1, line: 2203 in /home/forsake2/public_html/test/drupal-5.3/includes/common.inc(1347) : eval()'d code on line 4.
    * warning: DOMDocument::load() [function.DOMDocument-load]: Start tag expected, '<' not found in http://www.wowarmory.com/guild-info.xml?r=Boulderfist&n=Forsaken+Deity&p=1, line: 2203 in /home/forsake2/public_html/test/drupal-5.3/includes/common.inc(1347) : eval()'d code on line 4.

styro’s picture

As I said, my experience of XSL is pretty rudimentary and I've never used it with PHP before - but...

As far as I can tell your PHP code looks correct. I think the problems are with the XML bits.

One thing I would try is to save that XML data locally so you can edit it (at least until you can get it working).

Some rough ideas based on trying to decipher those error messages:

It looks like your XSL file doesn't have the XML declaration bit at the top eg: <?xml version="1.0" encoding="UTF-8"?>

And it looks like PHP doesn't like the <?xml-stylesheet type="text/xsl" href="/layout/guild-info.xsl"?> processing instruction (PI) in the XML data. That PI tells the browser which XSL transform to use on the data to render that flash looking HTML page from the raw XML - but you don't need that PI because you aren't using the browser and you have your own transform being used on your server. When I do "view source" on that page in Firefox I see the raw XML instead of the transformed HTML.

Also you might want to edit the XML data so that the <page ...> element starts on its own line below the PIs.

My untrained eyes seem to think your XSL is roughly correct, but I can't confirm that. Note: you might want to remove the presentational bits from the HTML output though - ie the bgcolor and align attributes.

After that though, I'm all out of ideas.

--
Anton
New to Drupal? | Troubleshooting FAQ
Example knowledge base built with Drupal

Summit’s picture

subscribing. Getting XML feeds to nodes is what I am interested in.
Greetings,
Martijn

wastrilith2k’s picture

I played around with this and actually found out the issue was mainly in the xslt file.

Here is the php code I placed in my node:

<?php

function HTTPRequest($url){ 
      $ch = curl_init(); 
      curl_setopt($ch,CURLOPT_URL,$url); 
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
      curl_setopt($ch,CURLOPT_MUTE,1); 
      curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]); 
      curl_setopt($ch, CURLOPT_TIMEOUT, 10); //times out after 10 
      curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); 
      $data = curl_exec ($ch); 
      curl_close ($ch); 
      return $data; 
}

$xmlDATA = HTTPRequest("http://www.wowarmory.com/guild-info.xml?r=Spirestone&n=Drakens+Dragoons&p=1");
$arguments = array('/_xml' => $xmlDATA);
$xsltproc = xslt_create();

xslt_set_encoding($xsltproc, 'UTF-8');

$filebase = getcwd ();
xslt_set_base($xsltproc,$filebase);

$html = xslt_process($xsltproc, 'arg:/_xml', "wowarmory.xslt", NULL, $arguments);
echo $html;
if (empty($html)) {
  die('XSLT processing error: '. xslt_error($xsltproc));
}
print($html);
xslt_free($xsltproc);
?>

The wowarmory.xslt file referenced is:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  
   <table border="1">
    <tr bgcolor="#000000">
      <th align="left">Name</th>
      <th align="left">Race</th>
      <th align="left">Class</th>
      <th align="left">Level</th>
      <th align="left">Rank</th>
    </tr>
    <xsl:for-each select="page/guildInfo/guild/members/character">
    <tr>
      <td><a href=""><xsl:value-of select="@name"/></a></td>
      <td><xsl:value-of select="@race"/></td>
      <td><xsl:value-of select="@class"/></td>
      <td><xsl:value-of select="@level"/></td>
      <td><xsl:value-of select="@rank"/></td>
    </tr>
    </xsl:for-each>
    </table>
</xsl:template>
</xsl:stylesheet>
wastrilith2k’s picture

I forgot I left something in there that was incorrect. The PHP code should be as follows:

<?php

function HTTPRequest($url){
      $ch = curl_init();
      curl_setopt($ch,CURLOPT_URL,$url);
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
      curl_setopt($ch,CURLOPT_MUTE,1);
      curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]);
      curl_setopt($ch, CURLOPT_TIMEOUT, 10); //times out after 10
      curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
      $data = curl_exec ($ch);
      curl_close ($ch);
      return $data;
}

$xmlDATA = HTTPRequest("http://www.wowarmory.com/guild-info.xml?r=Spirestone&n=Drakens+Dragoons&p=1");
$arguments = array('/_xml' => $xmlDATA);
$xsltproc = xslt_create();

xslt_set_encoding($xsltproc, 'UTF-8');

$html = xslt_process($xsltproc, 'arg:/_xml', "wowarmory.xslt", NULL, $arguments);

if (empty($html)) {
  die('XSLT processing error: '. xslt_error($xsltproc));
}
print($html);
xslt_free($xsltproc);
?>

This involved removing the $filebase portion of the code.

James

somes’s picture

the only change I can see here is the encoding "UTF-8" why ??

wastrilith2k’s picture

The filebase was also removed.

wastrilith2k’s picture

I tried using this today and now my connection times out and I don't get any XML from WoWArmory.com. I can take the URL in there and go straight to the site, so I am wondering if they blocked it. Has anyone else had any issues with this?

James