Jump to content

Archived

This topic is now archived and is closed to further replies.

forzatio

[SOLVED] errors with xslt parser

Recommended Posts

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

Share this post


Link to post
Share on other sites

I did not receive all of those errors, but your for-each should not be closed:

<xsl:for-each select="test/xml/"/>

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.