Outputting XML in PHP/HTML

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
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Outputting XML in PHP/HTML

Post by kendall »

hello,

I have a main php file which outputs xhtml but i have an include php file that dynamically generates xml which imports fragment xsl stylesheet

im trying to use the ob_start() functions to display this page but i dont seem to be getting it

can you give me some advice on how i can get this displayed?

Kendall
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

which page is "this" referring to?
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

Ok this is the process...
the main page

Code: Select all

<?php
some include stuff, databases connections
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CMS Home Page</title>
<script language="javascript" src="/cms/includes/cms.js" type="text/javascript"></script>
<link href="/cms/includes/cms_css.css" type="text/css" rel="stylesheet" />
</head>
<body>
<p><?php print "Hello ".$_SESSION['User']->name." Id Number#: ".$_SESSION['User']->userID; ?>
  You have:
  <?php 
if(isset($_SESSION['Grant'])) 
	print 'Grant Privileges<br/>';
if(isset($_SESSION['Edit']))
	print 'Add Privileges<br/>'; 
				 
?>
</p>
<table width="100%" border="0" cellpadding="5" cellspacing="0">
  <tr>
    <td width="25%">// ouputs the xml content 
<?php include('taskmenuoptions.php'); ?><? ob_end_clean(); ?></td>
    <td width="75%">&nbsp;</td>
  </tr>
</table>
</body>
</html>
the file that outputs the xml

Code: Select all

<?php
php includes and connection stuff
?>
header("Content-type: text/xml"); 
print "<?xml version=\"1.0\"?>\n";
print "<?xml-stylesheet type=\"text/xsl\" href=\"/cms/menus/list_menu.xsl\"?>\n";
print "<menus>\n";
$section = NULL;
while($menus = $sqlConn->fetchObject()){
	if($section != $menus->MenuGroup){
		if(isset($close_tag)){
			print "\t</section>\n";
			unset($close_tag);
		}
		$close_tag = true;
		$section = $menus->MenuGroup;
		printf("\t<section name=\"%s\">\n",$menus->MenuGroup);
	}
	// get menu items for each section
	printf("\t\t\t<menu id=\"%d\" name=\"%s\" link=\"%s\" contentid=\"%s\" parentid=\"%s\" order=\"%d\" site=\"%d\">\n",$menus->MenuID
					,$menus->MenuName
					,$menus->MenuLink
					,$menus->ContentID
					,$menus->MenuParent
					,$menus->NavOrder
					,$menus->Status
				);
	GetSubMenus($menus->MenuID);
}
print "\t</section>\n</menus>";
xsl stylesheet

Code: Select all

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- DWXMLSource="menus.xml" -->
<!DOCTYPE xsl:stylesheet  [
	<!ENTITY nbsp   " ">
	<!ENTITY copy   "©">
	<!ENTITY reg    "®">
	<!ENTITY trade  "&#8482;">
	<!ENTITY mdash  "&#8212;">
	<!ENTITY ldquo  "&#8220;">
	<!ENTITY rdquo  "&#8221;"> 
	<!ENTITY pound  "£">
	<!ENTITY yen    "¥">
	<!ENTITY euro   "&#8364;">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1"/>
  <xsl:template match="menus">
  <div>
<xsl:call-template name="section"/>
</div>
  </xsl:template>
  <xsl:template name="name" match="@name">
    <li><xsl:value-of select="@name"/></li>
  </xsl:template>
 <!-- <xsl:template name="MENU"> 
    <xsl:for-each select="MENU">
	<xsl:sort select="@NavOrder" data-type="number" order="ascending"/>
      <xsl:call-template name="MenuName"/>
	  	<xsl:if test="count(child::*) > 0">
        	<xsl:call-template name="MENU"/>
		</xsl:if>
    </xsl:for-each>
  </xsl:template>-->
   <xsl:template name="menu" match="menu"> 
    <xsl:for-each select="menu">
	<xsl:sort select="@order" data-type="number" order="ascending"/>
      <xsl:call-template name="name"/>
	  	<xsl:if test="count(child::*) > 0">
        	<ul><xsl:call-template name="menu"/></ul>
		</xsl:if>
    </xsl:for-each>
  </xsl:template>
   <xsl:template name="section" match="section">
   <ul>
 	 <xsl:for-each select="section">
	 	<xsl:call-template name="menu">
		</xsl:call-template>
	 </xsl:for-each>
	 </ul>
  </xsl:template>
</xsl:stylesheet>
the xml output

Code: Select all

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/cms/menus/list_menu.xsl"?>
<menus>
	<section name="pendings">
			<menu id="1111" name="View Pending Documents" link="index.php" contentid="" parentid="0" order="1" site="1">
			<menu id="232321" name="Add a Pending Document" link="index.php?action=add" contentid="" parentid="1111" order="2" status="1">
			</menu>
			</menu>
	</section>
	<section name="menus">
			<menu id="2222" name="Explore Website Menus" link="index.php" contentid="" parentid="0" order="3" site="1">
			<menu id="222213" name="Add Menu Item" link="index.php?action=add" contentid="" parentid="2222" order="4" status="1">
			</menu>
			<menu id="37736" name="View Document Library" link="docs/index.php" contentid="" parentid="2222" order="5" status="1">
			<menu id="624213" name="Add New Document" link="docs/index.php?action=add" contentid="" parentid="37736" order="6" status="1">
			</menu>
			</menu>
			</menu>
	</section>
	<section name="users">
			<menu id="3334" name="View CMS Users" link="index.php" contentid="" parentid="0" order="7" site="1">
			<menu id="3341" name="Add New User" link="index.php?action=add" contentid="" parentid="3334" order="8" status="1">
			</menu>
			<menu id="3330" name="Vew User Docs" link="userdocs/index.php" contentid="" parentid="3334" order="9" status="1">
			<menu id="333412" name="Add Item to User" link="userdocs/index.php?action=add" contentid="" parentid="3330" order="10" status="1">
			</menu>
			</menu>
			</menu>
	</section>
</menus>
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

This is what im getting when i execute the process

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CMS Home Page</title>
<script language="javascript" src="/cms/includes/cms.js" type="text/javascript"></script>
<link href="/cms/includes/cms_css.css" type="text/css" rel="stylesheet" />
</head>
<body>
<p>Hello Main Administrator Id Number#: TEST123  You have:
  Grant Privileges<br/>Add Privileges<br/></p>
<table width="100%" border="0" cellpadding="5" cellspacing="0">
  <tr>
    <td width="25%"><?xml version="1.0"?>

<?xml-stylesheet type="text/xsl" href="/cms/menus/list_menu.xsl"?>
<menus>
	<section name="pendings">
			<menu id="1111" name="View Pending Documents" link="index.php" contentid="" parentid="0" order="1" site="1">
			<menu id="232321" name="Add a Pending Document" link="index.php?action=add" contentid="" parentid="1111" order="2" status="1">
			</menu>
			</menu>
	</section>
	<section name="menus">
			<menu id="2222" name="Explore Website Menus" link="index.php" contentid="" parentid="0" order="3" site="1">

			<menu id="222213" name="Add Menu Item" link="index.php?action=add" contentid="" parentid="2222" order="4" status="1">
			</menu>
			<menu id="37736" name="View Document Library" link="docs/index.php" contentid="" parentid="2222" order="5" status="1">
			<menu id="624213" name="Add New Document" link="docs/index.php?action=add" contentid="" parentid="37736" order="6" status="1">
			</menu>
			</menu>
			</menu>
	</section>
	<section name="users">

			<menu id="3334" name="View CMS Users" link="index.php" contentid="" parentid="0" order="7" site="1">
			<menu id="3341" name="Add New User" link="index.php?action=add" contentid="" parentid="3334" order="8" status="1">
			</menu>
			<menu id="3330" name="Vew User Docs" link="userdocs/index.php" contentid="" parentid="3334" order="9" status="1">
			<menu id="333412" name="Add Item to User" link="userdocs/index.php?action=add" contentid="" parentid="3330" order="10" status="1">
			</menu>
			</menu>
			</menu>
	</section>

</menus></td>
    <td width="75%">ff</td>
  </tr>
</table>
</body>
</html>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Are you wanting to display the code or the XSL transformation of the code?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

well i want to display the transformed data.

Im trying not to use any php xml related functions as i really dont like php 4's handling of xml and php 5 isnt too popular with hosting packages where i'm at.

Kendall
Post Reply