|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-03-14 13:28 UTC] rrichards@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 31 14:00:01 2025 UTC |
Description: ------------ When generating childs of an element with a default namespace using DOMDocument->createElement() the namespace of the childs won't be set to the correct value. Reloading the DOMDocument using saveXML() and loadXML() fixes the Problem. Reproduce code: --------------- $xml = new DOMDocument("1.0","UTF-8"); $foo = $xml->createElementNS('urn:foo','foo'); $xml->appendChild($foo); $bar = $xml->createELement('bar','Bar using default namespace'); $foo->appendChild($bar); /* results in <foo xmlns="urn:foo"><bar>Bar using default namespace</bar></foo> */ $xsl = DOMDocument::Load('test.xsl'); $xslt = new xsltProcessor(); $xslt->importStylesheet($xsl); print($xslt->transformToXML($xml)); print("\n\nReload DOM\n"); $xml = DOMDocument::LoadXML($xml->saveXML()); print($xslt->transformToXML($xml)); -----------test.xsl------------- <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foo="urn:foo" > <xsl:output method="text" omit-xml-declaration = "yes"/> <xsl:template match="foo:foo"> foo:bars:<xsl:apply-templates select="foo:bar"/> bars:<xsl:apply-templates select="bar"/> </xsl:template> <xsl:template match="*"> - <xsl:value-of select="."/> </xsl:template> </xsl:stylesheet> Expected result: ---------------- foo:bars: - Bar using default namespace bars: Reload DOM foo:bars: - Bar using default namespace bars: Actual result: -------------- foo:bars: bars: - Bar using default namespace Reload DOM foo:bars: - Bar using default namespace bars: