【问题标题】:PHP XSLTProcessor Compilation errorPHP XSLTProcessor 编译错误
【发布时间】: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 标记在同一个问题中?还是我的心...无论如何,与号&amp; 是一个特殊的XML 实体,它的符号不能独立。请注意 XML 实体与 HTML 实体不同。

标签: php xml xslt


【解决方案1】:

尝试设置

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

load 调用之前。

【讨论】:

    猜你喜欢
    • 2021-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-14
    • 2011-12-17
    • 1970-01-01
    • 2012-09-14
    • 1970-01-01
    相关资源
    最近更新 更多