[PHP] Question about using XSLT_Process?
Hello, I'm trying to use xslt_process with $arguments like in the third example in the online documentation, but I'm not having any luck. I can run the same .xml and .xsl using the simple examples, but I cannot when using the $arguments example. I would really like to get this figured out, but I've run into a brick wall and I can't seem to understand why it doesn't work. I've pasted my .xml, .xsl and .php files below. Thanks, John This does transform the xml and produce results: --- ?php // Create an XSLT processor $xh = xslt_create(); xslt_set_base($xh, file://D:/Inetpub/wwwroot/phpxml/); // NEED TO FIGURE OUT HOW TO SPECIFY THE INPUT XML and XSL FILE LOCATIONS!!! // Process the XML $result = xslt_process($xh, 'test.XML', 'test.xsl'); if ($result){ // print SUCCESS, book.xml was transformed by book.xsl into result.xml; // print result.xml has the following contents\nbr/\n; // print pre\n; print $result; // print /pre; } else { print Sorry, failure!; print br/; echo xslt_error($xh); print br/; echo xslt_errno($xh); } xslt_free($xh); ? --- This does not: --- ?php echo one; // Grab the XSL and XML files $xsl = xmldoc(implode(,file(test.xsl))); $xml = xmldoc(implode(,file(test.xml))); // Set up the Arguments thingy $args = array( '/_xml'=$xml, '/_xsl'=$xsl ); // Create an XSLT processor $xh = xslt_create(); // Process the XML $result = xslt_process($xh, 'arg:/_xsl', 'arg:/_xml', null, $args); //$result = xslt_process($xh, 'files\book.XML', 'files\book.xsl', NULL, $args); if ($result){ // print SUCCESS, book.xml was transformed by book.xsl into result.xml; // print result.xml has the following contents\nbr/\n; print h2 Yes! /h2\n; print pre\n; print $result; print /pre; } else { print Sorry, failure!\n; print br/\n; echo xslt_error($xh); print br/\n; echo xslt_errno($xh); } xslt_free($xh); ? --- The XML File: --- ?xml version=1.0 encoding=UTF-8? book !-- Title of the book -- titleProfessional Php Programming (Programmer to Programmer)/title !-- Authors of the book -- textThis book has been authored by:/text authors author number=1Sascha Schumann/author author number=2Harish Rawat/author author number=3Jesus M. Castagnetto/author author number=4Deepak T. Veliath/author /authors !-- Image of the book -- textA picture of the book's cover: /text picturehttp://images.amazon.com/images/P/1861002963.01.MZZZ.jpg/pictu re !-- Pricing info-- textThe pricing of the book is as follows:/text prices priceList price: $49.99/price priceOur price: $39.99/price priceYou save: $10.00/price /prices !-- Other misc info-- textHere is some sundry info about the book:/text bookinfo typePaperback/type amazonrank6,337/amazonrank pages909/pages publisherWrox Press/publisher isbn1861002963/isbn size2.00 x 9.16 x 7.30/size urlhttp://www.amazon.com/exec/obidos/ASIN/1861002963/o/qid=986194881/sr=8- 1/ref=aps_sr_b_1_1/107-4263716-8514955/url /bookinfo /book --- The XSL File: --- ?xml version=1.0 encoding=UTF-8? xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform; xmlns:fo=http://www.w3.org/1999/XSL/Format; xsl:template match=/ htmlbody xsl:apply-templates/ /body/html /xsl:template !-- This is the title of the page -- xsl:template match=title bu xsl:value-of select=./ /u/b /xsl:template xsl:template match=text p/nbsp;b xsl:value-of select=./ /bbr/ /xsl:template xsl:template match=authors table xsl:apply-templates/ /tablebr/ /xsl:template xsl:template match=author tr td xsl:value-of select=number/. /td td xsl:value-of select=./ /td /tr /xsl:template xsl:template match=prices p/nbsp; table xsl:apply-templates/ /tablep/nbsp; /xsl:template xsl:template match=price tr td xsl:value-of select=./ /td /tr /xsl:template xsl:template match=bookinfo p/nbsp; xsl:apply-templates/ p/nbsp; /xsl:template xsl:template match=bookinfo/* xsl:choose xsl:when test=local-name(.)='type' bType:/b /xsl:when xsl:when test=local-name(.)='amazonrank' bAmazon rank:/b /xsl:when xsl:when test=local-name(.)='pages' bNumber of pages:/b /xsl:when xsl:when test=local-name(.)='publisher' bPublisher:/b /xsl:when xsl:when test=local-name(.)='isbn'
Re: [PHP] Question about using XSLT_Process?
You just need the XML and/or XSL as a string. xmldoc() is creating a DOM object, which xslt_process() can't use. In you example that does not work properly, change this: $xsl = xmldoc(implode(,file(test.xsl))); $xml = xmldoc(implode(,file(test.xml))); to not use xmldoc(), like this: $xsl = implode(,file(test.xsl)); $xml = implode(,file(test.xml)); xslt_process() should be happy with the strings in the arguments array. g.luck, ~Chris /\ \ / Microsoft Security Specialist: X The moron in Oxymoron. / \ http://www.thebackrow.net On Wed, 3 Jul 2002 [EMAIL PROTECTED] wrote: Hello, I'm trying to use xslt_process with $arguments like in the third example in the online documentation, but I'm not having any luck. I can run the same .xml and .xsl using the simple examples, but I cannot when using the $arguments example. I would really like to get this figured out, but I've run into a brick wall and I can't seem to understand why it doesn't work. I've pasted my .xml, .xsl and .php files below. Thanks, John This does transform the xml and produce results: --- ?php // Create an XSLT processor $xh = xslt_create(); xslt_set_base($xh, file://D:/Inetpub/wwwroot/phpxml/); // NEED TO FIGURE OUT HOW TO SPECIFY THE INPUT XML and XSL FILE LOCATIONS!!! // Process the XML $result = xslt_process($xh, 'test.XML', 'test.xsl'); if ($result){ //print SUCCESS, book.xml was transformed by book.xsl into result.xml; //print result.xml has the following contents\nbr/\n; //print pre\n; print $result; //print /pre; } else { print Sorry, failure!; print br/; echo xslt_error($xh); print br/; echo xslt_errno($xh); } xslt_free($xh); ? --- This does not: --- ?php echo one; // Grab the XSL and XML files $xsl = xmldoc(implode(,file(test.xsl))); $xml = xmldoc(implode(,file(test.xml))); // Set up the Arguments thingy $args = array( '/_xml'=$xml, '/_xsl'=$xsl ); // Create an XSLT processor $xh = xslt_create(); // Process the XML $result = xslt_process($xh, 'arg:/_xsl', 'arg:/_xml', null, $args); //$result = xslt_process($xh, 'files\book.XML', 'files\book.xsl', NULL, $args); if ($result){ //print SUCCESS, book.xml was transformed by book.xsl into result.xml; //print result.xml has the following contents\nbr/\n; print h2 Yes! /h2\n; print pre\n; print $result; print /pre; } else { print Sorry, failure!\n; print br/\n; echo xslt_error($xh); print br/\n; echo xslt_errno($xh); } xslt_free($xh); ? --- The XML File: --- ?xml version=1.0 encoding=UTF-8? book !-- Title of the book -- titleProfessional Php Programming (Programmer to Programmer)/title !-- Authors of the book -- textThis book has been authored by:/text authors author number=1Sascha Schumann/author author number=2Harish Rawat/author author number=3Jesus M. Castagnetto/author author number=4Deepak T. Veliath/author /authors !-- Image of the book -- textA picture of the book's cover: /text picturehttp://images.amazon.com/images/P/1861002963.01.MZZZ.jpg/pictu re !-- Pricing info-- textThe pricing of the book is as follows:/text prices priceList price: $49.99/price priceOur price: $39.99/price priceYou save: $10.00/price /prices !-- Other misc info-- textHere is some sundry info about the book:/text bookinfo typePaperback/type amazonrank6,337/amazonrank pages909/pages publisherWrox Press/publisher isbn1861002963/isbn size2.00 x 9.16 x 7.30/size urlhttp://www.amazon.com/exec/obidos/ASIN/1861002963/o/qid=986194881/sr=8- 1/ref=aps_sr_b_1_1/107-4263716-8514955/url /bookinfo /book --- The XSL File: --- ?xml version=1.0 encoding=UTF-8? xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform; xmlns:fo=http://www.w3.org/1999/XSL/Format; xsl:template match=/ htmlbody xsl:apply-templates/ /body/html /xsl:template !-- This is the title of the page -- xsl:template match=title bu xsl:value-of select=./ /u/b /xsl:template xsl:template match=text p/nbsp;b xsl:value-of select=./ /bbr/ /xsl:template xsl:template match=authors table xsl:apply-templates/