xslt_process()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
brentwatson
Forum Newbie
Posts: 4
Joined: Tue Dec 10, 2002 11:17 am

xslt_process()

Post 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
User avatar
QWERTY
Forum Newbie
Posts: 20
Joined: Sat Jun 29, 2002 10:57 am
Location: Slovenia

...

Post 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 ... ?
brentwatson
Forum Newbie
Posts: 4
Joined: Tue Dec 10, 2002 11:17 am

More complicated now....

Post 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
brentwatson
Forum Newbie
Posts: 4
Joined: Tue Dec 10, 2002 11:17 am

A tad more info

Post 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
User avatar
QWERTY
Forum Newbie
Posts: 20
Joined: Sat Jun 29, 2002 10:57 am
Location: Slovenia

...

Post by QWERTY »

brentwatson
Forum Newbie
Posts: 4
Joined: Tue Dec 10, 2002 11:17 am

Got it working! :)....

Post 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
Post Reply