1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/ext/xsl/tests/gh21357_2.phpt
ndossche 284fd7779d Fix GH-21357: XSLTProcessor works with DOMDocument, but fails with Dom\XMLDocument
Registering namespace after the parsing is too late because parsing can
fail due to attributes referencing namespaces.
So we have to register fake namespaces before the parsing.
However, the clone operation reconciles namespaces in the wrong way, so
we have to clone via an object.

Closes GH-21371.
2026-03-11 22:31:03 +01:00

36 lines
1.1 KiB
PHP

--TEST--
GH-21357 (XSLTProcessor works with \DOMDocument, but fails with \Dom\XMLDocument)
--EXTENSIONS--
dom
xsl
--CREDITS--
jacekkow
--FILE--
<?php
$xsl = '<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:old="http://something/old/"
xmlns:new="http://something/new/">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="old:*">
<xsl:element name="{local-name()}" xmlns="http://something/new/" >
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>';
$dom = Dom\XMLDocument::createFromString($xsl);
$xsl = new XSLTProcessor();
$xsl->importStylesheet($dom);
var_dump($xsl->transformToXml(\Dom\XMLDocument::createFromString('<test xmlns="http://something/old/"/>')));
?>
--EXPECT--
string(138) "<?xml version="1.0"?>
<test xmlns="http://something/new/" xmlns:ns_1="http://www.w3.org/2000/xmlns/" ns_1:xmlns="http://something/old/"/>
"