XSLT transformation of dynamic xml by php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

XSLT transformation of dynamic xml by php

Post by hame22 »

Hi I have an xsl file and a php file that dynamicaly produces XML page from a mysq database.

I now need another php page to perform the transformations of these pages.

The code I have at present thows up the following errors

\r\n"; //print "\r\n"; print "\t\r\n"; print ''; print ''.$description.''; print "\t\r\n"; print " version source metadatascheme format location copyr_value class_value "; print ""; ?>
Warning: Sablotron error on line 26: XML parser error 4: not well-formed (invalid token) in /usr/local/home/httpd/vhtdocs/fenman/web/activities/dev/keywords/dynamic.php on line 20

My code is as follows

php file to produce xml:

Code: Select all

<?php

header(&quote;content-type: text/xml&quote;);


//$prod_id = $_GET&#1111;'product_id'];

mysql_connect('localhost', 'fenman_act_user', 'mfx671zdv');
 
 mysql_select_db('fenman_act_db') or exit(&quote;cannot connect&quote;);

$result = mysql_query(&quote;Select * from activities where product_id = 'DTL01'&quote;);




$row = mysql_fetch_array($result);

$title = $row&#1111;'title'];
$description = $row&#1111;'long_desc'];
$keyword = $row&#1111;'keywords'];




print &quote;<?xml version=\&quote;1.0\&quote; encoding=\&quote;UTF-8\&quote; ?>\r\n&quote;;
//print &quote;<?xml-stylesheet type=\&quote;text/xsl\&quote; href=\&quote;xml2.xsl\&quote; 


print &quote;<Lom
	xmlns:ims_lom=\&quote;http://www.imsglobal.org/xsd/imsmd_v1p2\&quote;
	xmlns:xsi=\&quote;http://www.w3.org/2001/XMLSchema-instance\&quote;
	
>\r\n&quote;;

print &quote;\t<general>\r\n&quote;;

print '<title>'.$title.' </title>';
print '<description>'.$description.'</description>';


print &quote;\t</general>\r\n&quote;;

print &quote;<lifecycle>
		<version>version</version>
		<source>source</source>
	</lifecycle>

	<metametadata>
		<metadatascheme>metadatascheme</metadatascheme>
	</metametadata>

	<technical>
		<format>format</format>
		<location link=\&quote;location\&quote;>location</location>
	</technical>

	<rights>
		<copyrightandotherrestrictions>
			<value>copyr_value</value>
		</copyrightandotherrestrictions>
	</rights>

	
	<classification>
		<purpose>
			<value>class_value</value>
		</purpose>
	</classification>&quote;;


		

	

print &quote;</Lom>&quote;;

?>
xsl file:

Code: Select all

<?xml version=&quote;1.0&quote; encoding=&quote;ISO-8859-1&quote;?><xsl:stylesheet version=&quote;1.0&quote;
xmlns:xsl=&quote;http://www.w3.org/1999/XSL/Transform&quote;>
<xsl:output method=&quote;html&quote;/>
<xsl:template match=&quote;/&quote;>
  <html>
  <head><title>test</title></head>
  <body>
    <h2>Activity</h2>

<xsl:for-each select =&quote;Lom/general&quote;>
<h3> Activity Name: <p><B> <xsl:value-of select=&quote;title&quote;/></B></p></h3>
</xsl:for-each>


    <xsl:for-each select=&quote;Lom/technical&quote;>
    
      <p>Activity format: <xsl:value-of select=&quote;format&quote;/></p>
 </xsl:for-each>
<xsl:for-each select=&quote;Lom/technical/location&quote;>
<a href=&quote;{@link}&quote;> 
                    
                 

      <p>Click to access</p>
  </a>  
    
    </xsl:for-each>
    




  </body>
  </html>
</xsl:template></xsl:stylesheet>

and the php code to transform

Code: Select all

<?php
// Gonna contain PHP-XML output


$xh = xslt_create();

// Read plain PHP-XML output
$xmlData = fopen ('test.php', &quote;r&quote;);

// Stack up output into one String
while ($line = fgets ($xmlData))
  $xml .= $line;
  print $xml;
  
  $arguments = array(
     '/_xml' => $xml,
);

// Process the document
$result = xslt_process($xh, 'arg:/_xml', 'xml2.xsl', NULL, $arguments); 

// Print out your transformed document
echo $result;

xslt_free($xh); 

?>

this problem has been bugging me for days, can perform the transformation within the one file but I want to use 3 seperate files.

Could any one help!??

thanks in advance

alex
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Code: Select all

// Read plain PHP-XML output
$xmlData = fopen ('test.php', "r");
you are mistaken here... this outputs your phpcode... not the generated xml

a possible solution (this way the php script is executed and returns xml)

Code: Select all

$xmldata = file_get_contents('http://localhost/test.php');
Post Reply