这是我第一次尝试以字符串的形式对从cURL返回的xml执行转换。我有一个我认为正确编写的PHP,因为我至少可以回显$xml_data
中包含的字符串。但是,每当我尝试通过浏览器查看php时,我都会得到一个空白页面(和源代码)。我究竟做错了什么?任何指针都会有所帮助和赞赏..
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"]);
?>
XSL(注意这还不完整,此时我只是试图从屏幕上的xml中获取一些数据并设置样式)
<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>
如果我在php中包含echo $xml_data
,我会得到以下xml字符串
<?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>
答案 0 :(得分:1)
来自http://php.net/manual/en/xsltprocessor.transformtoxml.php
使用libxml_get_last_error()
或libxml_get_errors()
检索转换中的错误。