PHP XSLTProcessor编译错误

时间:2017-09-26 10:56:48

标签: php xml xslt

无法使用样式表进行转换,样式表在xsl:text节点中有实体。如果我把& some;我没有错误和空输出;外部xsl:文本节点。

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>

收到错误:

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信息

libxml2 Version => 2.9.5
ibxslt Version => 1.1.29
libxslt compiled against libxml Version => 2.9.4

1 个答案:

答案 0 :(得分:1)

尝试设置

$xsl = new DOMDocument;
$xsl->substituteEntities = TRUE;
load来电之前