Skip to main content
Known Participant
July 23, 2006
Answered

MM_XSLTransform error every time in PHP page

  • July 23, 2006
  • 3 replies
  • 632 views
When I apply an XSL Transformation to a PHP page, the page displays with an MM_XSLTransform error saying the XML file is not a valid XML document -- even though it absolutely is valid XML. This is totally reproducable.

Here's a simple example:


library.xml:

<?xml version="1.0" encoding="iso-8859-1"?>
<library>
<owner>Mister Reader</owner>
<book>
<isbn>1-2345-6789-0</isbn>
<title>All About XML</title>
<author>John Doe</author>
<language>English</language>
<price currency="usd">24.95</price>
</book>
<book>
<isbn>9-8765-4321-0</isbn>
<title>CSS Made Simple</title>
<author>Jane Smith</author>
<language>English</language>
<price currency="usd">19.95</price>
</book>
</library>

library.xsl:

<xsl:stylesheet version="1.0" xmlns:xsl=" http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1"/>
<xsl:template match="/">
<h1><xsl:value-of select="library/owner"/>'s Library</h1>
<xsl:for-each select="library/book">
<p><em><xsl:value-of select="title"/></em>
by <xsl:value-of select="author"/>
(ISBN <xsl:value-of select="isbn"/>)</p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

library.php:

<?php
//XMLXSL Transformation class
require_once('includes/MM_XSLTransform/MM_XSLTransform.class.php');
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
$mm_xsl = new MM_XSLTransform();
$mm_xsl->setXML("library.xml");
$mm_xsl->setXSL("library.xsl");
echo $mm_xsl->Transform();
?>
</body>
</html>



When viewing the file library.php, the following error is displayed in the browser, followed by the raw XML:

library.xml is not a valid XML document.
Non-static method DOMDocument::loadXML() should not be called statically, assuming $this from incompatible context in file library.xml.


I wonder whether there is a problem with the include file MM_XSLTransform, version 0.6.2. Since that include file begins with a "TODO" note from the programmer, I wonder whether it's not quite release-ready.

Anyone else having this problem?




Environment:
- Testing Server on localhost
- Windows XP Pro SP2
- Dreamweaver 8.0.2
- PHP 5.1.4
- MySQL 5.0.2.1
- PHP MyAdmin 2.8.1
This topic has been closed for replies.
Correct answer Newsgroup_User
Jon9999 wrote:
> I wonder whether there is a problem with the include file MM_XSLTransform,
> version 0.6.2. Since that include file begins with a "TODO" note from the
> programmer, I wonder whether it's not quite release-ready.

It was release-ready. It worked fine in PHP 5.0, but changes in PHP
5.1.4 caused it to break. As I understand, Adobe is preparing a PHP
hotfix that solves several problems caused by the 8.0.2 updater. It also
fixes this one.

In the meantime, you can easily hand fix it yourself.

Comment out line 301, which looks like this:

$xml = DOMDocument::loadXML($content);

Then insert the following two new lines immediately below:

$doc = new DOMDocument();
$err = $doc->loadXML($content);

The rest of the script then continues with this:

restore_error_handler();

So, when you have finished, lines 301-304 will look like this:

//$xml = DOMDocument::loadXML($content);
$doc = new DOMDocument();
$err = $doc->loadXML($content);
restore_error_handler();

Just in case you're interested in what the problem was: line 301 uses
loadXML() as a static method of the DOMDocument class. As of PHP 5.1.4,
this isn't allowed. The substitute lines create a DOMDocument object,
and then call the method on the new object.

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/

3 replies

Inspiring
July 23, 2006
Jon9999 wrote:
> I absolutely LOVE your PHP for Dreamweaver book, by the way! It's an amazing piece of work.

Thanks, Jon. Glad you like it.

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/
Jon9999Author
Known Participant
July 23, 2006
David,

Thank you so much for that answer.

I absolutely LOVE your PHP for Dreamweaver book, by the way! It's an amazing piece of work.

Cheers,
-jon
Newsgroup_UserCorrect answer
Inspiring
July 23, 2006
Jon9999 wrote:
> I wonder whether there is a problem with the include file MM_XSLTransform,
> version 0.6.2. Since that include file begins with a "TODO" note from the
> programmer, I wonder whether it's not quite release-ready.

It was release-ready. It worked fine in PHP 5.0, but changes in PHP
5.1.4 caused it to break. As I understand, Adobe is preparing a PHP
hotfix that solves several problems caused by the 8.0.2 updater. It also
fixes this one.

In the meantime, you can easily hand fix it yourself.

Comment out line 301, which looks like this:

$xml = DOMDocument::loadXML($content);

Then insert the following two new lines immediately below:

$doc = new DOMDocument();
$err = $doc->loadXML($content);

The rest of the script then continues with this:

restore_error_handler();

So, when you have finished, lines 301-304 will look like this:

//$xml = DOMDocument::loadXML($content);
$doc = new DOMDocument();
$err = $doc->loadXML($content);
restore_error_handler();

Just in case you're interested in what the problem was: line 301 uses
loadXML() as a static method of the DOMDocument class. As of PHP 5.1.4,
this isn't allowed. The substitute lines create a DOMDocument object,
and then call the method on the new object.

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/