Page 1 of 1

xslt_process()

Posted: Tue Dec 10, 2002 11:17 am
by brentwatson
Hey All,

I'm trying to use xslt_process() but can't seem to use absolute paths to my XML & XSL files. I'm getting my XML off of a different server than what my PHP script lives on, so I need to be able to specify an absolute path.

Thanks,

Brent

...

Posted: Tue Dec 10, 2002 12:59 pm
by QWERTY
Try something like that:

Code: Select all

$fpXSLT = fopen( $strURLGetXSLT, "r" );
    				$strXSLTContent = fread( $fpXSLT, 600000 );
				fclose( $fpXSLT );
And than:

Code: Select all

$arrayArgumentsї'/_xml'] = $strXMLContent; // You can do the same with XML file as XSLT (fopen, fread, ...)
$arrayArgumentsї'/_xsl'] = $strXSLTContent;

$strHTML = &xslt_process( $parserXSLT, "arg:/_xml", "arg:/_xsl", NULL, $arrayArguments );
This should work ... ?

More complicated now....

Posted: Wed Dec 11, 2002 9:26 am
by brentwatson
Well, my problem just got more complicated now :S

Now I need to add an attribute to my XML documents root then pass it into xslt_process.

the set up of my document is as such:
<xdocument>
<xpage>
<xbody>
etc., etc.
</xbody>
</xpage>
</xdocument>

I need to add an attribute called "formAction" to xdocument before applying the transformation [xslt_process()].

Thanks for all the help!

Brent Watson

A tad more info

Posted: Wed Dec 11, 2002 10:04 am
by brentwatson
A bit of extra info:

I've successfully added an attribute to the root like so:

$XMLAttribFile = domxml_open_file("sample.xml");
$root = $XMLAttribFile->root();
$root->set_attribute("formAction", "testTESTtest");

Now inorder to use the XML file in xslt_process I need to somehow turn my XML Dom file ($XMLAttribFile) into a string....then we should be home-free....

Anyone know how I could turn this object into a string??!!

Thanks once again,

Brent Watson

...

Posted: Wed Dec 11, 2002 11:52 am
by QWERTY

Got it working! :)....

Posted: Wed Dec 11, 2002 2:03 pm
by brentwatson
Got it working :D

I used dump_mem() to pass the object into a string...
Here is my code incase someone else comes across the same sort of problem:

Code: Select all

$XMLFile = "http:\\path_to_xml";
$XSLFile = "http:\\path_to_xsl";
$XMLAttribFile = domxml_open_file($XMLFile);
$root = $XMLAttribFile->root();
$root->set_attribute("formAction", "myTestAttribute");

$fpXSLT = fopen($XSLFile, "r"); 
	$strXSLTContent = fread($fpXSLT, 6000000); 
fclose( $fpXSLT );

$strXMLContent=$XMLAttribFile->dump_mem(true);

$arrayArguments&#1111;'/_xml'] = $strXMLContent;
$arrayArguments&#1111;'/_xsl'] = $strXSLTContent;

$xh = xslt_create();
$result = xslt_process($xh,"arg:/_xml", "arg:/_xsl", NULL, $arrayArguments);
if ($result)
    print $result;
else 
&#123;
    print " Error: " . xslt_error($xh) . 
    print " Error code " . xslt_errno($xh);
&#125;
xslt_free($xh);
Also, remeber to do a xslt_set_base($xh,"file://C:/your_xsl_dir/"); before your xslt_process() if you have <xsl:include>'s in your XSL.

Thanks for all the help!!

Brent Watson