I am working on updating my script to move our code from Ubuntu 12.04 (PHP 5.3.10) to Ubuntu 14.04 (PHP 5.5.9), however $result = $proc->transformToXml($xml); keeps returning NULL and I don't know why.
- I've var_dump()-ed pretty much every variable/object and checked it's contents
- Googled on many different search terms
As stated this used to work in Ubuntu 12.04 and according to (what I can find) there has been no changes between different PHP versions regarding the used classes (DomDocument, XSLTProcessor).
How can I get $result to contain the correctly parsed XML output?
This is my PHP code:
$xml = new DomDocument();
$xml->loadXML($xml_file_contents, LIBXML_NOERROR);
$xml->normalizeDocument(); //Whether included or left out doesn't seem to make a difference
$xsl = new DomDocument();
$xsl->loadXML($xsl_file_contents);
$proc = new XSLTProcessor();
$proc->importStylesheet($xsl);
$result = $proc->transformToXml($xml);
The XML:
<vac:body>
<vac:kanaal type="generiek">
<vac:vraag>Lorem Ipsum dolar sit amet</vac:vraag>
<vac:antwoord
xmlns="http://www.w3.org/1999/xhtml">
<vac:antwoordTekst/>
<vac:antwoordTekstErvoor/>
<vac:antwoordTekstOrigineel/>
<vac:antwoordTekstErna/>
<vac:antwoordProductVeld>
<![CDATA[<p>Lorem Ipsum dolar sit amet</p>]]>
</vac:antwoordProductVeld>
<vac:antwoordAdres/>
</vac:antwoord>
<vac:toelichting
xmlns="http://www.w3.org/1999/xhtml">
<![CDATA[]]>
</vac:toelichting>
<vac:onderwaterantwoord>
<vac:onderwaterantwoordTekst/>
<vac:onderwaterantwoordProductVeld/>
</vac:onderwaterantwoord>
<vac:formulieren/>
<vac:contactinfo/>
</vac:kanaal>
<vac:verwijzingProduct resourceIdentifier="1337">Lorem ipsum</vac:verwijzingProduct>
<vac:verwijzingVac resourceIdentifier="1337-01">Lorem Ipsum dolar sit amet</vac:verwijzingVac>
<vac:verwijzingVac resourceIdentifier="1337-02">Lorem ipsum dolar sit amet</vac:verwijzingVac>
</vac:body>
And the XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:call-template name="text">
<xsl:with-param name="node" select="/body/kanaal/antwoord/antwoordTekst" />
</xsl:call-template>
<xsl:call-template name="text">
<xsl:with-param name="node" select="/body/kanaal/antwoord/antwoordProductVeld" />
</xsl:call-template>
<xsl:call-template name="address">
<xsl:with-param name="node" select="/body/kanaal/antwoord/antwoordAdres" />
</xsl:call-template>
<xsl:if test="/body/kanaal/verwijzingOverigeInfo" >
<ul>
<xsl:for-each select="/body/kanaal/verwijzingOverigeInfo" >
<xsl:call-template name="moreinfo">
<xsl:with-param name="node" select="self::node()" />
</xsl:call-template>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:template>
<xsl:template name="text">
<xsl:param name="node" />
<xsl:if test="normalize-space($node/text())">
<xsl:value-of select="$node"/>
</xsl:if>
</xsl:template>
<xsl:template name="address">
<xsl:param name="node" />
<xsl:for-each select="$node/instantie">
<p class="vac_address">
<xsl:for-each select="*">
<xsl:call-template name="address_element"/>
</xsl:for-each>
</p>
</xsl:for-each>
</xsl:template>
<xsl:template name="address_element">
<xsl:if test=". != ''">
<xsl:element name="span">
<xsl:attribute name="class">
<xsl:value-of select ="name(.)"/>
</xsl:attribute>
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:element>
</xsl:if>
</xsl:template>
<xsl:template name="moreinfo">
<xsl:param name="node" />
<li>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="$node/@resourceIdentifier" />
</xsl:attribute>
<xsl:value-of select="$node" />
</xsl:element>
</li>
</xsl:template>
</xsl:stylesheet>
PHP Warning: DOMDocument::loadXML(): Namespace prefix vac on <nodename> is not defined in Entitya bunch of times, the XML itself seems to be still correctly beeing loaded into the DomDocument (when I usesaveXML()it returns the same XML output). TheloadXML()also returns true which according to the PHPDoc means it loaded the XML succesfully.