Last active
August 29, 2015 13:57
-
-
Save hubgit/9669288 to your computer and use it in GitHub Desktop.
Demo script showing separation of doctype from source document during XSLTProcessor::transformToDoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// prepare the XSL processor | |
$stylesheet = new DOMDocument; | |
$stylesheet->loadXML('<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"/>'); | |
$processor = new XSLTProcessor; | |
$processor->importStylesheet($stylesheet); | |
// load the XML (with a doctype) | |
$doc = new DOMDocument; | |
$doc->loadXML('<?xml version="1.0"?> | |
<!DOCTYPE article PUBLIC "-//example//EN" "http://example.org/dtd"> | |
<article/>'); | |
printf("Doctype ID: %s\n", $doc->doctype->publicId); // Doctype ID: -//example//EN | |
printf("Next sibling: %s\n\n", $doc->doctype->nextSibling->nodeName); // 'article' | |
// write out the original document (has doctype) | |
print $doc->saveXML(); | |
/* | |
<?xml version="1.0"?> | |
<!DOCTYPE article PUBLIC "-//example//EN" "http://example.org/dtd"> | |
<article/> | |
*/ | |
// transform the document (transformToDoc or transformToXML) | |
// this is where the doctype gets unexpectedly separated | |
// normally $output would be used, but is ignored here | |
$output = $processor->transformToDoc($doc); | |
// the doctype is still there, but has no nextSibling | |
printf("\nDoctype ID: %s\n\n", $doc->doctype->publicId); // Doctype ID: -//example//EN | |
//printf("Next sibling: %s\n", $doc->doctype->nextSibling->nodeName); // no nextSibling | |
// write out the original document again (no doctype) | |
print $doc->saveXML(); | |
/* | |
<?xml version="1.0"?> | |
<article/> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment