0

This is my first attempt to perform a transform on an xml returned from cURL in the form of a string. I have a php that I think is written properly as I can at least echo back the string contained in $xml_data . However, whenever I attempt to view the php through a browser I get a blank page (and source). What am I doing wrong? Any pointers would be helpful and appreciated..

php

<?php
$ch = curl_init("http://somewhere.com/deliver_xml.php?release_week=20140126");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml_data=curl_exec($ch);
curl_close($ch);

$xmlDoc = new DOMDocument();
$xml->$xml_data;

$xslDoc = new DOMDocument();
$xslDoc->load("new_releases.xsl");

$proc = new XSLTProcessor();
$proc->importStylesheet($xslDoc);

$xmlDoc->loadXML($xml_data);

echo $proc->transformToXML($xmlDoc);

$proc->setParameter('', 'albumid', $_POST["id"]);

?>

The XSL (note this is not complete, at this point I'm just attempting to get some of the data from xml on the screen and style it)

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">

   <xsl:output method="html" />

    <xsl:template match="/">
    <html><body>
     <div style="position: relative; font-weight: bold; font-size: 24pt;">
        New music for the week of <xsl:value-of select="release_week_start"/></div>
      <xsl:for-each select="/album">
              <a xmlns="http://www.w3.org/1999/xhtml"
                href="{../@id}.xhtml">
                <xsl:value-of select="album/artist"/>
              </a>
      </xsl:for-each>        
 </body></html>



</xsl:stylesheet>

If I include echo $xml_data in my php I get the following xml string

<?xml version="1.0"?>
<new_release>
 <release_week_start date="January 26, 2014">
  <album id="AD1" albumart="http://peachfields.com/hvcc/ciss227/images/no_art.png">
   <artist>After The Disco</artist>
   <name>Broken Bells</name>
   <year>2014</year>
   <release_date>January 31, 2014</release_date>
   <label>Columbia Records</label>
   <disc>1</disc>
   <totaldiscs>1</totaldiscs>
   <tracklist>
     <track id="1">Perfect World</track>
     <track id="2">After The Disco</track>
     <track id="3">Holding On For Life</track>
     <track id="4">Leave It Alone</track>
     <track id="5">The Changing Lights</track>
     <track id="6">Control</track>
     <track id="7">Lazy Wonderland</track>
     <track id="8">Medicine</track>
     <track id="9">No Matter What You're Told</track>
     <track id="10">The Angel And The Fool</track>
     <track id="11">The Remains of Rock And Roll</track>
   </tracklist>
  </album>
  <album id="CC1" albumart="http://peachfields.com/hvcc/ciss227/images/no_art.png">
   <artist>Casting Crowns</artist>
   <name>Thrive</name>
   <year>2014</year>
   <release_date>January 28, 2014</release_date>
   <label>Reunion Records</label>
   <disc>1</disc>
   <totaldiscs>1</totaldiscs>
   <tracklist>
     <track id="1">Thrive</track>
     <track id="2">All You've Ever Wanted</track>
     <track id="3">Just Be Held</track>
     <track id="4">You Are The Only One</track>
     <track id="5">Broken Together</track>
     <track id="6">Love You With The Truth</track>
     <track id="7">This Is Now</track>
     <track id="8">Dream For You</track>
     <track id="9">Follow Me</track>
     <track id="10">Heroes</track>
     <track id="11">House Of Their Dreams</track>
     <track id="12">Waiting On The Night To Fall</track>
    </tracklist>
   </album>
 </release_week_start>
</new_release>
7
  • Okay so sounds like you are getting the XML correctly, I'm thinking the error then is with your transform. try var_dump ($proc->transformToXML($xmlDoc);) To see if its actually returning null. If it doesn't print anything on the browser, then you have a fatal error somewhere. Commented Apr 20, 2015 at 2:01
  • Thanks @RobMullins I tried what you suggested and it printed out bool(false) , So I'm assuming my xsl is not written properly? Commented Apr 20, 2015 at 2:10
  • Hard to say for sure, but transformToXML($xmlDoc) returns false on error. Insert this after your transform: print_r(libxml_get_errors()), it should give you detailed error info. Commented Apr 20, 2015 at 2:13
  • I just noticed I forgot to use </xsl:template> to close off the template (kind of embarrassing!). it now prints out my html string New music for the week of " (a literal double quote mark) Commented Apr 20, 2015 at 2:16
  • Yup, I just ran a test on it and returned: [Fatal Error] xsl.xslt:19:3: The element type "xsl:template" must be terminated by the matching end-tag "</xsl:template>". Commented Apr 20, 2015 at 2:19

1 Answer 1

1

From http://php.net/manual/en/xsltprocessor.transformtoxml.php

Use libxml_get_last_error() or libxml_get_errors() to retrieve errors in transformations.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.