I asked this question before but I think I worded it in a confusing way, so I'll try again.

Lets say I have a file called data.xml which calls template.xsl as a transforming template. How can I get the transformed results of data.xml to appear as content within a node?

I have previously done an SSI-like function as a PHP tag within the body of my node, but the same technique doesn't work with XML and I don't know enough about it to know why.

Anyone have any ideas?

Thanks!

Sean

Comments

nedjo’s picture

Do you have (can you post) sample code you're working with?

I'd assume offhand that you should be able to do the XSL transformation and then output the result as part of the node body.

What library are you using for the XSL transformation?

seaneffel’s picture

I have two simple files for you to see:

XML data:
http://www.coolidge.org/a_showtimes.xml

XSL template:
http://www.coolidge.org/aa.xsl

Calling the XML file in a compliant browser should parse the sucker the way I intend. But when I use this code, which I normally use for including HTML files, I get either an error or no result, depending on which madness onset as I was experimenting:

>

<? include("http://www.coolidge.org/a_showtimes.xml"); 

<?php/>

nedjo’s picture

Maybe something like:


$filename = "http://www.coolidge.org/a_showtimes.xml";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
$node->body .= $contents;

(Or do you need to use fsockopen for a web address?)

seaneffel’s picture

I get this nasty little error with that snip of code. I admit that I don't understand any code...

warning: filesize(): Stat failed for http://www.coolidge.org/a_showtimes.xml (errno=2 - No such file or directory) in /home/coolidge/drupal/includes/common.inc(1093) : eval()'d code on line 4.
warning: fread(): Length parameter must be greater than 0. in /home/coolidge/drupal/includes/common.inc(1093) : eval()'d code on line 4.

Thanks for your help this far!

chandar’s picture

Hi

I tried this coding snippet but could not get any content as desired. Interestingly, there was no error message also.

Also pls let me know how a xml file which is available in the www folder can be called here. The coressponding xsl also lying there.

Thanks in advance.

edwardvielmetti’s picture

The code here looks like it would be a start:

http://www.zend.com/php5/articles/php5-xmlphp.php#Heading17

Requires PHP5. I haven't tested it myself.

Edward Vielmetti, Ann Arbor, MI

seaneffel’s picture

"Fatal error: Cannot instantiate non-existent class: domdocument in /home/coolidge/drupal/includes/common.inc(1098) : eval()'d code on line 3"

Like I said, I am at a barbaric level of understanding here, so when I get this message I just don't understand it. All I know is, didn't work.

I wish there were some simple resources to look at, I am sure that there MUST have been some people who did this before me and made it work.

vizechef’s picture

I recommend you not to use pure XML/XSL since there are way too many browser incompatibilities.
Some time ago I played around with that and found a way to transform XML using PHP with Sablotron, but this is subject to the condition that your isp provides the Sablotron PHP extension. Call phpinfo() and look for xml/xslt extensions or rather the expat XML parser.

nedjo’s picture

provides cross-browser XSLT methods:

http://sourceforge.net/projects/sarissa