Jump to content


Photo

[SOLVED] errors with xslt parser


  • Please log in to reply
6 replies to this topic

#1 forzatio

forzatio
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 26 February 2007 - 11:52 PM

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

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 27 February 2007 - 05:02 AM

I did not receive all of those errors, but your for-each should not be closed:
<xsl:for-each select="test/xml/"/>
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 forzatio

forzatio
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 27 February 2007 - 07:55 AM

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.

#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 27 February 2007 - 02:23 PM

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

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#5 forzatio

forzatio
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 28 February 2007 - 10:39 AM

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.

#6 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 01 March 2007 - 12:01 AM

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.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#7 forzatio

forzatio
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 01 March 2007 - 10:14 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users