<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: PHP question.</title>
	<link>http://ask.metafilter.com/7520/PHP-question/</link>
	<description>Comments on Ask MetaFilter post PHP question.</description>
	<pubDate>Wed, 26 May 2004 15:05:16 -0800</pubDate>
	<lastBuildDate>Wed, 26 May 2004 15:05:16 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: PHP question.</title>
		<link>http://ask.metafilter.com/7520/PHP-question</link>	
		<description>Ok, another PHP question... this one less stupid than my last one (hopefully). XML/XSLT.... [mi] &lt;br /&gt;&lt;br /&gt; I have some generated XML (from a php script that builds from a directory and contents)... I used and modified some code to do a transform:&lt;br&gt;
&lt;small&gt;&lt;br&gt;
&lt; ?phpbr&gt;
&lt;br&gt;
/**&lt;br&gt;
 *&lt;br&gt;
 * A class to transform XML through XSLT using PHP4 Sablotron extension&lt;br&gt;
 *&lt;br&gt;
 */&lt;br&gt;
&lt;br&gt;
 #######################################################################&lt;br&gt;
 ## file extended by Daniel Unterberger (d.u@mail.com)&lt;br&gt;
 ## changes: some  php:eval&apos;s added&lt;br&gt;
&lt;br&gt;
class xsltTransform&lt;br&gt;
{&lt;br&gt;
&lt;br&gt;
   var $xsl_file;&lt;br&gt;
   var $xml_file;&lt;br&gt;
   var $fileName;&lt;br&gt;
&lt;br&gt;
   /**&lt;br&gt;
     * Constructor to the xsl_transform ticket&lt;br&gt;
     *&lt;br&gt;
     * @param $xsl_file The XSLT file containing the transformation info&lt;br&gt;
     * @param $xml_file The XML file containing the actual data&lt;br&gt;
     * @see readFile()&lt;br&gt;
     */&lt;br&gt;
   function xsltTransform($xsl_file = &apos;&apos;, $xml_file = &apos;&apos;)&lt;br&gt;
   {&lt;br&gt;
       if($xsl_file{0} == &quot;/&quot;) # this is a relative path, so use the file&lt;br&gt;
			 {&lt;br&gt;
			 	 $this-&amp;gt;xsl_string = &quot;file://&quot;.$_SERVER[&apos;DOCUMENT_ROOT&apos;].$xsl_file;&lt;br&gt;
			 }&lt;br&gt;
			 else&lt;br&gt;
			 {&lt;br&gt;
			   $this-&amp;gt;xsl_string = $this-&amp;gt;readFile($xsl_file,&apos;php:eval&apos;);&lt;br&gt;
			 }&lt;br&gt;
			 &lt;br&gt;
			 if($xml_file{0} == &quot;/&quot;) # this is a relative path, so use the file&lt;br&gt;
			 {&lt;br&gt;
			 	 $this-&amp;gt;xml_string = &quot;file://&quot;.$_SERVER[&apos;DOCUMENT_ROOT&apos;].$xml_file;&lt;br&gt;
			 }&lt;br&gt;
			 else&lt;br&gt;
			 {&lt;br&gt;
			   $this-&amp;gt;xml_string = $this-&amp;gt;readFile($xml_file);&lt;br&gt;
			 }&lt;br&gt;
       &lt;br&gt;
   }&lt;br&gt;
&lt;br&gt;
   /**&lt;br&gt;
     * Function to read through the file&lt;br&gt;
     *&lt;br&gt;
     * @param $fileName Which file to read?&lt;br&gt;
     *&lt;br&gt;
     */&lt;br&gt;
   function readFile($fileName,$php_eval=&quot;&quot;)&lt;br&gt;
   {&lt;br&gt;
       // get contents of a file into a string&lt;br&gt;
       $fd = fopen( $fileName, &quot;r&quot; );&lt;br&gt;
			 while (!feof ($fd)) {&lt;br&gt;
		   			 $content .= fgets($fd, 4096); #?rtrim&lt;br&gt;
       }&lt;br&gt;
			 fclose( $fd );&lt;br&gt;
&lt;br&gt;
       ##################################################&lt;br&gt;
       ## extension by Daniel Unterberger (d.u@mail.com)&lt;br&gt;
&lt;br&gt;
       while ( $php_eval and ( $pos_start=strpos($content,&apos;&lt;php :eval&gt;&apos;) ))&lt;br&gt;
       {&lt;br&gt;
         $pos_end=strpos($content,&apos;&lt;/php&gt;&apos;);&lt;br&gt;
         $content=substr($content,0,$pos_start).&lt;br&gt;
                   eval( substr($content,$pos_start+10,$pos_end-$pos_start-10) ).&lt;br&gt;
                   substr($content,$pos_end+11);&lt;br&gt;
       }&lt;br&gt;
&lt;br&gt;
       if ($GLOBALS[&quot;debug&quot;]==&quot;ON&quot;) print &quot;&lt;xmp&gt;$content&lt;/xmp&gt;&quot;;&lt;br&gt;
           ## see xslt-file for debuggin if you call page.php?debug=ON (remove on life-server)&lt;br&gt;
&lt;br&gt;
       ###################################################&lt;br&gt;
       ## end extension&lt;br&gt;
&lt;br&gt;
       return $content;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
   }&lt;br&gt;
&lt;br&gt;
   /**&lt;br&gt;
     * Function to apply the actual transformation&lt;br&gt;
     *&lt;br&gt;
     */&lt;br&gt;
   function applyTransformation()&lt;br&gt;
   {&lt;br&gt;
	 		 $xh = xslt_create(); &lt;br&gt;
       # $this-&amp;gt;result = &apos;&apos;;&lt;br&gt;
       $this-&amp;gt;result = xslt_process($xh, $this-&amp;gt;xml_string, $this-&amp;gt;xsl_string);&lt;br&gt;
       &lt;br&gt;
			 if(!$this-&amp;gt;result)&lt;br&gt;
			 {&lt;br&gt;
			   print (&quot;Transformation failed; Error String:&quot;.xslt_error($xh).&quot;; Err #:&quot;.xslt_errno($xh).&quot;&lt;hr&gt;&quot;);&lt;br&gt;
				 print (&quot;XSL:&lt;pre&gt;-&quot;.$this-&amp;gt;xsl_string.&quot;-&lt;/pre&gt;&lt;hr&gt;&quot;);&lt;br&gt;
				 print (&quot;XML:&lt;pre&gt;-&quot;.$this-&amp;gt;xml_string.&quot;-&lt;/pre&gt;&quot;); &lt;br&gt;
			 }&lt;br&gt;
			 &lt;br&gt;
			 xslt_free($xh); &lt;br&gt;
       return $this-&amp;gt;result;&lt;br&gt;
   }&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
// End of class, do not remove&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
?&amp;gt; &lt;br&gt;
&lt;/&gt;&lt;/small&gt;&lt;br&gt;
&lt;br&gt;
now the if I generate the XML and save it to the file system, then give the function xsltTransform the actual file path the transform work fine. However, if I read it from the webserver using http:// (where it was generated from) I can print it to the screen. &lt;br&gt;
However, but the call to $this-&amp;gt;result = xslt_process($xh, $this-&amp;gt;xml_string, $this-&amp;gt;xsl_string); in applyTransformation fails indicating that the XML is badly formed (error 4). Any advice from our PHP gurus?</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2004:site.7520</guid>
		<pubDate>Wed, 26 May 2004 06:03:15 -0800</pubDate>
		<dc:creator>pissfactory</dc:creator>
		
			<category>php</category>
		
			<category>xml</category>
		
			<category>xslt</category>
		
			<category>xsltTransform</category>
		
	</item> <item>
		<title>By: holloway</title>
		<link>http://ask.metafilter.com/7520/PHP-question#148797</link>	
		<description>xslt_process() is a bit touchy and tries to guess whether you&apos;re submitting a string of xml or a path.&lt;br&gt;
&lt;br&gt;
What&apos;s your input to each function? Can you make reproduce it with a simpler example?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2004:site.7520-148797</guid>
		<pubDate>Wed, 26 May 2004 15:05:16 -0800</pubDate>
		<dc:creator>holloway</dc:creator>
	</item>
	</channel>
</rss>
