2011-03-03 73 views
0

我碰到XSLTProcessor中一些錯誤的XSLT處理:問題與PHP

XSLTProcessor::transformToDoc() [<a href='function.XSLTProcessor-transformToDoc'>function.XSLTProcessor-transformToDoc</a>]: Invalid or inclomplete context

XSLTProcessor::transformToDoc() [<a href='function.XSLTProcessor-transformToDoc'>function.XSLTProcessor-transformToDoc</a>]:

XSLTProcessor::transformToDoc() [<a href='function.XSLTProcessor-transformToDoc'>function.XSLTProcessor-transformToDoc</a>]: xsltValueOf: text copy failed in

這是解析這個XSLT線:

<xsl:apply-templates select="page/sections/section" mode="subset"/> 

的部分是:

<xsl:template match="page/sections/section" mode="subset"> 
    <a href="#{shorttitle}"> 
     <xsl:value-of select="title"/> 
    </a> 
    <xsl:if test="position() != last()"> | </xsl:if> 
</xsl:template> 

的部分解析的XML是:

<shorttitle>About</shorttitle> 
    <title>#~ About</title> 

PHP的XSLT代碼是:

$xslt = new XSLTProcessor(); 
$XSL = new DOMDocument(); 

$XSL->load($xsltFile, LIBXML_NOCDATA); 

$xslt->importStylesheet($XSL); 

print $xslt->transformToXML($XML); 

我對錯誤的懷疑是由於內容。我沒有得到與Firefox的XSLT渲染這些錯誤,我也沒有得到負載上backend.I'm無效XML文檔沒有收到錯誤,它只是在transformToXML功能。

+1

您向我們顯示的代碼似乎沒有任何問題。這通常意味着您沒有向我們顯示的代碼有問題。 – 2011-03-03 08:52:39

+0

所有錯誤的指向在transformToXML – monksy 2011-03-03 13:49:00

回答

1

對我的作品(PHP5.3)。

我稍微修改了代碼,使其運行,但我看不出與XSLT任何PB。 我沒有遇到你描述的信息。

PHP

<?php 

    $xsltFile = "a.xslt"; 
    $xmlFile = "a.xml"; 

    $xslt = new XSLTProcessor(); 
    $xsl = new DOMDocument(); 
    $xml = new DOMDocument(); 

    $xsl->load($xsltFile, LIBXML_NOCDATA); 
    $xml->load($xmlFile, LIBXML_NOCDATA); 

    $xslt->importStylesheet($xsl); 

    print $xslt->transformToXML($xml); 

    ?> 

XML

<page> 
<sections> 
<section> 
<shorttitle>http://about.com/about.php</shorttitle> 
<title>#~ About</title> 
</section> 
</sections> 
</page> 

XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:output method="html"/> 

<xsl:template match="/"> 
<xsl:apply-templates select="page/sections/section" mode="subset"/> 
</xsl:template> 

<xsl:template match="page/sections/section" mode="subset"> 
    <a href="#{shorttitle}"> 
     <xsl:value-of select="title"/> 
    </a> 
    <xsl:if test="position() != last()"> | </xsl:if> 
</xsl:template> 

</xsl:stylesheet> 
+0

你說得對行...有件事更重要的問題。這很奇怪。 – monksy 2011-03-03 15:30:59

+0

源xml中沒有奇怪的字符(或&entity;)?你可以嘗試用簡單的xml來查看pb是來自輸入還是軟輸入。 – 2011-03-03 15:38:03

+0

這顯然是一個問題,顯示其他地方和報告在不同的位置。我沒有從DomDocument加載XML的問題。我只是使用了你的XSLT,它可以和原始的XML一起工作,所以它提供了一些關於PHP正在拋棄的XSLT。 – monksy 2011-03-03 15:51:58

-2

如果你在錯誤與運行XSLTProcessor中,它往往是值得檢查您的系統正在使用的libxml和版本的libxslt的版本(參見:http://www.php.net/manual/en/xsl.requirements.php)。檢查這些最簡單的方法是看的

<?php phpinfo(); ?> 

輸出您正在尋找的「libxml的版本」和「反對的libxslt的libxml版本編譯」。您可能正在使用您使用的版本不支持的語法或結構。

如果這不是問題的根源,我們可能需要查看更多的代碼,xml和xslt,以便我們擁有合適的上下文。正如Alain的答案所表明的那樣,通過完成你的語法有些任意可執行,沒有明顯的問題。