Forum Moderators: coopster
I have an issue with parsing xml to html using the code below that the <img> and <br> tags are not closed.
I have found a few different opinions regarding php bugs etc but cannot fin a resolve
PHP example code
$xml2 = new DOMDocument;
if ($xml2->loadXML('<?xml version="1.0" encoding="iso-8859-1"?' .'>' .$XML_content)){
$xsl = new DOMDocument;
$xsl->load(xsl("article_publish.xsl"));
// Configure the transform
$proc = new XSLTProcessor;
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsl); // attach the xsl rules
$finalContentRightNav = htmlspecialchars_decode($proc->transformToXML($xml2));
XSLT header code
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" exclude-result-prefixes="php">
<xsl:output method="html" encoding="ISO-8859-1" indent="no"/>
<xsl:namespace-alias stylesheet-prefix="php" result-prefix="xsl" />
Is there a way to make the tags close properly when pringed to html? Or os it a php version problem. I'm using PHP 5.2.0-8
Or do I need a regex to add the end tag in after processing :(
NOTE: I am calling some php functions and I have tried <xsl:output method="xml", which causes grief re javascript and some html layouts etc etc
It's killing my validation instantly, and me slowly!
Thanks
Trent
[edited by: eelixduppy at 7:08 pm (utc) on Feb. 8, 2008]
[edit reason] disabled smileys [/edit]
I found a solution which seem to work fine for me incase some one is looking for a solution.
original code
// Configure the transform
$proc = new XSLTProcessor;
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsl);
$finalContentHTML = $proc->transformToXML($xml);
New code
// Configure the transform
$proc = new XSLTProcessor;
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsl);
$finalContentHTML_Doc = $proc->transformToDoc($xml);
$finalContentHTML = $finalContentHTML_Doc->saveXML();
Cheers