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\n<br/>\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\n<br/>\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 -->
> <title>Professional Php Programming (Programmer to Programmer)</title>
>
> <!-- Authors of the book -->
> <text>This book has been authored by:</text>
> <authors>
> <author number="1">Sascha Schumann</author>
> <author number="2">Harish Rawat</author>
> <author number="3">Jesus M. Castagnetto</author>
> <author number="4">Deepak T. Veliath</author>
> </authors>
>
> <!-- Image of the book -->
> <text>A picture of the book's cover: </text>
>
> <picture>http://images.amazon.com/images/P/1861002963.01.MZZZZZZZ.jpg</pictu
> re>
>
> <!-- Pricing info-->
> <text>The pricing of the book is as follows:</text>
> <prices>
> <price>List price: $49.99</price>
> <price>Our price: $39.99</price>
> <price>You save: $10.00</price>
> </prices>
>
> <!-- Other misc info-->
> <text>Here is some sundry info about the book:</text>
> <bookinfo>
> <type>Paperback</type>
> <amazonrank>6,337</amazonrank>
> <pages>909</pages>
> <publisher>Wrox Press</publisher>
> <isbn>1861002963</isbn>
> <size>2.00 x 9.16 x 7.30</size>
>
> <url>http://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="/">
> <html><body>
> <xsl:apply-templates/>
> </body></html>
> </xsl:template>
>
> <!-- This is the title of the page -->
> <xsl:template match="title">
> <b><u>
> <xsl:value-of select="."/>
> </u></b>
> </xsl:template>
>
> <xsl:template match="text">
> <p/> <b>
> <xsl:value-of select="."/>
> </b><br/>
> </xsl:template>
>
> <xsl:template match="authors">
> <table>
> <xsl:apply-templates/>
> </table><br/>
> </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/> <table>
> <xsl:apply-templates/>
> </table><p/>
> </xsl:template>
>
> <xsl:template match="price">
> <tr>
> <td>
> <xsl:value-of select="."/>
> </td>
> </tr>
> </xsl:template>
>
> <xsl:template match="bookinfo">
> <p/>
> <xsl:apply-templates/>
> <p/>
> </xsl:template>
>
> <xsl:template match="bookinfo/*">
> <xsl:choose>
> <xsl:when test="local-name(.)='type'">
> <b>Type:</b>
> </xsl:when>
> <xsl:when test="local-name(.)='amazonrank'">
> <b>Amazon rank:</b>
> </xsl:when>
> <xsl:when test="local-name(.)='pages'">
> <b>Number of pages:</b>
> </xsl:when>
> <xsl:when test="local-name(.)='publisher'">
> <b>Publisher:</b>
> </xsl:when>
> <xsl:when test="local-name(.)='isbn'">
> <b>ISBN #:</b>
> </xsl:when>
> <xsl:when test="local-name(.)='size'">
> <b>Dimensions in inches:</b>
> </xsl:when>
> <xsl:when test="local-name(.)='url'">
> <b>More info from this link:</b>
> </xsl:when>
> </xsl:choose>
> <xsl:value-of select="."/>
> <br/>
> </xsl:template>
>
> </xsl:stylesheet>
> -----------------------------------------------------------------------
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php