DOMDocument::nodeValue converts entities after XSL transform

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
Yragael
Forum Newbie
Posts: 1
Joined: Mon May 05, 2008 11:02 am

DOMDocument::nodeValue converts entities after XSL transform

Post by Yragael »

Hello all,

I need some help to understand the DOMElement::nodeValue behavior regarding entities. Here is a little XML file :

Code: Select all

<?xml version="1.0" encoding="iso-8859-1"?>
<input><</input>
and here is a little XSL stylesheet :

Code: Select all

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="input">
    <output>
        <xsl:value-of select="." />
    </output>
</xsl:template>
</xsl:stylesheet>
and here is a little PHP code which transforms the XML document using the XSL stylesheet and displays the nodeValue of the documentElement :

Code: Select all

<html>
<body>
<?php
$xmlDocument = new DOMDocument ();
$xmlDocument->load ("test.xml");
$xmlStylesheet = new DOMDocument ();
$xmlStylesheet->load ("test.xsl");
$xslTransfom = new XSLTProcessor ();
$xslTransfom->importStylesheet ($xmlStylesheet);
$xmlDocument = $xslTransfom->transformToDoc ($xmlDocument);
echo ($xmlDocument->documentElement->firstChild->nodeValue);
?>
</body>
</html>
My surprise : the output is "<" instead of "<", which means that the entity has been converted. This should not have happened unless I had specified the disable-output-escaping attribute in the <xsl:value-of>, right ? By the way, if I display the contents of the document after the transformation :

Code: Select all

echo ($xmlDocument->saveXML ());
then the "<" is not converted :
<output><</output>
May somebody help me to understand this behavior ? Thanx.
Post Reply