【发布时间】:2017-09-26 10:56:48
【问题描述】:
无法使用样式表进行转换,该样式表在 xsl:text 节点中有实体。如果我放 &some; ,我没有错误和空输出外部 xsl:text 节点。
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
【问题讨论】:
-
PHP 和 XSLT 标记在同一个问题中?还是我的心...无论如何,与号
&是一个特殊的XML 实体,它的符号不能独立。请注意 XML 实体与 HTML 实体不同。