denoteone Posted November 22, 2010 Share Posted November 22, 2010 Trying to get everything in one file. I have an external data source that has 3 different XML files located on it. I am writing a php script that sits on my server and based on the GET variable I want to read a specific XML file and add a specific XSL style sheet to it then echo it to the browser. What I cant have is 3 different .XSL files siting on my server or the data source. So if there is some way I can save the XSL info as a variable and somehow apply all from my one PHP script that would be great. So far this is what I have: <?PHP $view = $_GET['view']; $xml_data = "http://externalserver.com/" . $view .".xml"; $handle = fopen($xml_data, 'r'); $Data = fread($handle, 512); fclose($handle); $old ='<?xml version="1.0" encoding="utf-8"?>'; //Right here is my biggest challange I dont wont the style sheets on the same server or any others for that matter since the server I am running this script on can not get out to the internet since it is behind a firewall. I was thinking of creating the XSL files on the fly and then saving them next to this script. But I would like to keep everything in just 1 file if at all possible. $new ='<?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet href="style.xsl" type="text/xsl"?>'; $final_xml = str_replace($old, $new, $Data); echo $final_xml; ?> the url would be http://www.myserver.com/getxml.php?view=weather Link to comment https://forums.phpfreaks.com/topic/219416-php-xml-xsl/ Share on other sites More sharing options...
requinix Posted November 22, 2010 Share Posted November 22, 2010 I don't believe you can. However you can reuse that PHP script to serve the XSL stuff. Then, besides looking for ?view= to get the XML, you look for ?style= to get the XSL. Link to comment https://forums.phpfreaks.com/topic/219416-php-xml-xsl/#findComment-1137753 Share on other sites More sharing options...
denoteone Posted November 22, 2010 Author Share Posted November 22, 2010 Technically that should work right? I mean all its doing is calling the same script twice. Then I can break the script up with an if statement based on the GET variable. Does that sound right? Link to comment https://forums.phpfreaks.com/topic/219416-php-xml-xsl/#findComment-1137772 Share on other sites More sharing options...
requinix Posted November 22, 2010 Share Posted November 22, 2010 Yeah, basically. Link to comment https://forums.phpfreaks.com/topic/219416-php-xml-xsl/#findComment-1137797 Share on other sites More sharing options...
denoteone Posted November 23, 2010 Author Share Posted November 23, 2010 Ok so I am calling the same page to set the .XSL style sheet but am getting the dreaded "Error loading stylesheet: Parsing an XSLT stylesheet failed." so the url calls the script that gets the xml file based on the GET variable and it adds the style sheet by calling the same page with a new GET variable. below is my script is this possible? <?PHP ini_set("display_errors","2"); ERROR_REPORTING(E_ALL); header('Content-type: text/xml'); $view = $_GET['view']; if(isset($_GET['xsl_style'])) { $style = '<?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> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>'; echo $style; }else{ $xml_data = "http://www.website.com/STRATA/" . $view .".xml"; $handle = fopen($xml_data, 'r'); $Data = fread($handle, 10000); fclose($handle); $old ='<?xml version="1.0" encoding="ISO-8859-1"?>'; $new ='<?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet href="http://www.website.com/STRATA/get_view.php?xsl_style='. $view .'" type="text/xsl"?>'; $final_xml = str_replace($old, $new, $Data); echo $final_xml; } ?> Link to comment https://forums.phpfreaks.com/topic/219416-php-xml-xsl/#findComment-1138239 Share on other sites More sharing options...
denoteone Posted November 23, 2010 Author Share Posted November 23, 2010 Trying to use firebug to see what is going wrong since I am only getting the XSLT error and no php error. Link to comment https://forums.phpfreaks.com/topic/219416-php-xml-xsl/#findComment-1138425 Share on other sites More sharing options...
denoteone Posted November 23, 2010 Author Share Posted November 23, 2010 I got it. My ini_set("display_errors","2"); ERROR_REPORTING(E_ALL); was adding a notice to the header of the XSL style sheet. I removed it and it is working fine. Link to comment https://forums.phpfreaks.com/topic/219416-php-xml-xsl/#findComment-1138432 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.