Jump to content

[SOLVED] errors with xslt parser


forzatio

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

Link to comment
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.

Link to comment
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.