1

Cannot make transformation with stylesheet, which has entity inside xsl:text node. I've got no errors and empty output if I put &some; outside xsl:text node.

test.php

$xml = new DOMDocument;
$xml->load('test.xml');

$xsl = new DOMDocument;
$xsl->load('test.xsl');

$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl);

echo $proc->transformToXML($xml);

test.xml

<?xml version="1.0" ?>
<test>123</test>

test.xsl

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE xsl:stylesheet [ <!ENTITY some "22323"> ]>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


    <xsl:output method="text" />

    <xsl:template match="/">
        <xsl:text>&some;</xsl:text>
    </xsl:template>

</xsl:stylesheet>

Got error:

Warning: XSLTProcessor::importStylesheet(): xsltParseTemplateContent: xslt:text content problem in /Users/stexe/Repos/umi.cms.2/test.php on line 13

Call Stack:
    0.0003     226288   1. {main}() /Users/stexe/Repos/umi.cms.2/test.php:0
    0.0009     228424   2. XSLTProcessor->importStylesheet() /Users/stexe/Repos/umi.cms.2/test.php:13

Os X, PHP 5.4.45 (Homebrew)

PHP info:

libxml2 Version => 2.9.5
ibxslt Version => 1.1.29
libxslt compiled against libxml Version => 2.9.4
1
  • PHP and XSLT tagged in same question? Be still my heart...Anyways, the ampersand, &, is a special XML entity and its symbol cannot standalone. And do note XML entities are not the same as HTML entities. Commented Sep 26, 2017 at 11:46

1 Answer 1

1

Try setting

$xsl = new DOMDocument;
$xsl->substituteEntities = TRUE;

before the load call.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.