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/auto_registration_namespaces_new_dom.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

44 lines
1.2 KiB
PHP

--TEST--
Auto-registration of namespaces in XSL stylesheet with new DOM
--EXTENSIONS--
dom
xsl
--SKIPIF--
<?php
require __DIR__.'/skip_upstream_issue113.inc';
?>
--FILE--
<?php
$sheet = Dom\XMLDocument::createFromString(<<<XML
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl"
xmlns:str="http://exslt.org/strings"
xmlns:xsdl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
<xsl:template match="/root">
<xsl:value-of select="php:function('strtoupper', string(./hello))"/>
<xsl:value-of select="test:reverse(string(./hello))"/>
</xsl:template>
</xsl:stylesheet>
XML);
// Make sure it will auto-register urn:test
$sheet->documentElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:test', 'urn:test');
$input = Dom\XMLDocument::createFromString(<<<XML
<root>
<hello>World</hello>
</root>
XML);
$processor = new XSLTProcessor();
$processor->importStylesheet($sheet);
$processor->registerPHPFunctions();
$processor->registerPHPFunctionNS('urn:test', 'reverse', 'strrev');
echo $processor->transformToXML($input), "\n";
?>
--EXPECT--
WORLDdlroW