2017-09-26 107 views
0

无法使用样式表进行转换,该样式表具有xsl:text节点内的实体。如果我将&some;放在xsl:text节点之外,则没有错误和空输出。PHP XSLTProcessor编译错误

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(自制)

PHP信息

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

PHP和XSLT标记在同一个问题?仍然是我的心...无论如何,&符号&是一个特殊的XML实体,它的符号不能独立。注意XML实体与HTML实体不同。 – Parfait

回答

1

尝试load调用之前设置

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