1

I'm getting a few errors from XSLTProcessor:

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

Which is parsing this XSLT Line:

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

The section is:

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

The XML that the section is parsing is:

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

The PHP XSLT Code is:

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

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

$xslt->importStylesheet( $XSL );

print $xslt->transformToXML( $XML );

My suspicion about the the errors is due to content. I'm not getting these errors with Firefox's XSLT rendering, nor am I getting an invalid XML document on the backend.I'm not getting errors on the load, its just on the transformToXML function.

2
  • 1
    There doesn't seem to be anything wrong with the code you've shown us. That usually means there is something wrong with the code you haven't shown us. Commented Mar 3, 2011 at 8:52
  • all of the errors point to the line at transformToXML Commented Mar 3, 2011 at 13:49

2 Answers 2

1

Works for me (php5.3).

I modified slightly the code to make it run but I can't see any pb with the XSLT. I did not encounter the message you describe.

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>
Sign up to request clarification or add additional context in comments.

3 Comments

You're right ... theres something more to the issue. This is quite weird.
No strange characters (or &entity;) in the source xml ? You could try with a simple xml to see if the pb is from the input or the soft.
This is obviously an issue that is showing up else where and reporting in a different location. I'm not getting an issue with loading the XML from the DomDocument. I just used your XSLT and it works with the original XML so its something about the XSLT that php is throwing a fit over.
-1

If you are running in to errors with XSLTProcessor, it is often worth checking the version of the libxml and libxslt versions that your system is using (see: http://www.php.net/manual/en/xsl.requirements.php). The easiest way to check these is to look at the output of

<?php phpinfo(); ?>

You are looking for the "libxml Version" and the "libxslt compiled against libxml Version". You may be using syntax or structure that is not supported by the version you use.

If this is not the source of your problem, we will likely need to see more of the code, xml and xslt so that we have the proper context. As Alain's answer indicates, by completing your syntax somewhat arbitrarily to be executable, there are no immediate problems apparent.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.