1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
--TEST--
cloneDocument
--EXTENSIONS--
xsl
dom
--FILE--
<?php
$xml = new DOMDocument;
$xml->loadXML('<?xml version="1.0"?><root><foo>hello</foo></root>');
function test() {
global $xml;
$xml->documentElement->firstChild->textContent = "bye";
}
$xsl = new DOMDocument;
$xsl->loadXML(<<<XML
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" version="1.0">
<xsl:template match="/root">
<xsl:value-of select="php:function('test')"/>
<xsl:value-of select="//root/foo"/>
</xsl:template>
</xsl:stylesheet>
XML);
$xslt = new XSLTProcessor;
$xslt->registerPHPFunctions();
$xslt->cloneDocument = true;
$xslt->importStylesheet($xsl);
echo $xslt->transformToXml($xml);
$xslt = new XSLTProcessor;
$xslt->registerPHPFunctions();
$xslt->cloneDocument = false;
$xslt->importStylesheet($xsl);
echo $xslt->transformToXml($xml);
?>
--EXPECT--
<?xml version="1.0"?>
hello
<?xml version="1.0"?>
bye
|