forzatio Posted February 26, 2007 Share Posted February 26, 2007 Hi there, I'm trying to parse a simple xml file with its xslt, I want to parse the output with php. However I get errors and there is no output. below is the xml , xslt and the php script code. I Hope we can resolve what's wrong. XML File: <?xml version="1.0" encoding="ISO-8859-1"?> <test> <xml>something</xml> </test> XSLT File: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> </tr> <xsl:for-each select="test/xml/"/> <tr> <td><xsl:value-of select="something"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> PHP-parser <?php /* load the xml file and stylesheet as domdocuments */ $xsl = new DomDocument(); $xsl->load("xslt.xslt"); $inputdom = new DomDocument(); $inputdom->load("xmlding.xml"); /* create the processor and import the stylesheet */ $proc = new XsltProcessor(); $xsl = $proc->importStylesheet($xsl); $proc->setParameter(null, "titles", "Titles"); /* transform and output the xml document */ $newdom = $proc->transformToDoc($inputdom); print $newdom->saveXML(); ?> Warning: DOMDocument::load() [function.DOMDocument-load]: Namespace prefix xsl on output is not defined Warning: DOMDocument::load() [function.DOMDocument-load]: Extra content at the end of the document Warning: XSLTProcessor::importStylesheet() [function.XSLTProcessor-importStylesheet]: compilation error Warning: XSLTProcessor::importStylesheet() [function.XSLTProcessor-importStylesheet]: xsltParseStylesheetProcess : empty stylesheet Warning: XSLTProcessor::transformToDoc() [function.XSLTProcessor-transformToDoc]: No stylesheet associated to this object Fatal error: Call to a member function saveXML() on a non-object Quote Link to comment Share on other sites More sharing options...
effigy Posted February 27, 2007 Share Posted February 27, 2007 I did not receive all of those errors, but your for-each should not be closed: <xsl:for-each select="test/xml/"/> Quote Link to comment Share on other sites More sharing options...
forzatio Posted February 27, 2007 Author Share Posted February 27, 2007 I did not receive all of those errors, but your for-each should not be closed: <xsl:for-each select="test/xml/"/> Ok I fixed that, though with this stylesheet I keep getting errors. I tried some other stylesheet which does work, but I don't know why this example xslt doesn't work. Quote Link to comment Share on other sites More sharing options...
effigy Posted February 27, 2007 Share Posted February 27, 2007 It's complaining about the xsl namespace not being defined. Is it sensitive to the line break here, perhaps? <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> Quote Link to comment Share on other sites More sharing options...
forzatio Posted February 28, 2007 Author Share Posted February 28, 2007 It's complaining about the xsl namespace not being defined. Is it sensitive to the line break here, perhaps? <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> It's not fixed with it unfortunately. bump for me please. Quote Link to comment Share on other sites More sharing options...
effigy Posted March 1, 2007 Share Posted March 1, 2007 The culprit is the trailing slash on for-each's path: test/xml/; remove it. Also, change "something" to "." to get the element's content. Quote Link to comment Share on other sites More sharing options...
forzatio Posted March 1, 2007 Author Share Posted March 1, 2007 The culprit is the trailing slash on for-each's path: test/xml/; remove it. Also, change "something" to "." to get the element's content. thanks, indeed the foreach path wasn't right there now it's just "test", and I changed value of select to subchild "xml"/ now it works fine Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.