Jump to content

New To Xml. How Should I Do This?


MrFish
 Share

Recommended Posts

So my project is to make some kind of fancy message that you will see on a site if there are messages available. For example, this one will check your browser and tell you if it's a good browser. Instead of just making a hard copy of the tabbed layout I wanted it to be multi-purposed. Like if there is a new exciting feature or two and I wanted this to popup for member who have just signed in and haven't seen it yet. So I thought I would do this with XML. It goes as follows-

<tab name="Chrome"><mtitle>Message Title</mtitle><message>This is the message of the tab. Pretty simple.</message></tab>

It only consists of 3 tags so far but once I get it down I'll expand to more information. I want it to look something like this-tabbedmessageconept.jpgAnd it currently looks something like this-http://mrfishtests.byethost17.com/How can I use Php/Javascript/xml to make a script that turns every <tab> into a tab, <mtitle> into a title, etc. I want this to have the ability to have several tabs but easy to edit. I'm currently using fopen to get the file with the xml (wich I want to stay a php file in case I want to get information for that specific message).

<?php$file = fopen('includes/blackoutmessagelogs.php', "r+");while(!feof($file)){	echo fgets($file) . '<br />';}fclose($file);?>

Link to comment
Share on other sites

You'll have to use PHP's DOM or XSL or XMLReader extensions for that. fopen() isn't going to cut it.The idea in all cases is that you take the XML, and turn it into the proper (X)HTML. The client receives only the resulting HTML. You could use JavaScript, but that will surely create more problems along the way.If you can tell me how would these tabs look in (X)HTML (code wise), I can help you with the XML-to-(X)HTML translation.

Edited by boen_robot
Link to comment
Share on other sites

Just for reference, this is the code I've tried to produce, based on the first demo at Dynamic Drive.

<ul id="tabs" class="shadetabs"><li><a href="?tab=1" rel="#default" class="selected">Message Title</a></li></ul><div id="tabsContent"><p>This is the message of the tab. Pretty simple.</p></div><script type="text/javascript" src="ajaxtabs/ajaxtabs.js">  /************************************************ Ajax Tabs Content script v2.1- © Dynamic Drive DHTML code library (www.dynamicdrive.com)* This notice MUST stay intact for legal use* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code***********************************************/ </script><script type="text/javascript">  var countries=new ddajaxtabs("tabs", "tabsContent")countries.setpersist(true)countries.setselectedClassTarget("link") //"link" or "linkparent"countries.init() </script>

Here's a sample (incomplete and untested!) XSLT:

<?xml version='1.0'?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:param name="tabIndex" select="1" /><xsl:param name="tab" select="/*/tab[$tabIndex]/@name" /><xsl:template match="/*"><ul>	<xsl:apply-templates /></ul><div id="tabsContent"><p><xsl:apply-templates match="/*/tab[$tabIndex]"/></p></div><script type="text/javascript" src="ajaxtabs/ajaxtabs.js">  /************************************************ Ajax Tabs Content script v2.1- © Dynamic Drive DHTML code library (www.dynamicdrive.com)* This notice MUST stay intact for legal use* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code***********************************************/ </script><script type="text/javascript">  var countries=new ddajaxtabs("tabs", "tabsContent")countries.setpersist(true)countries.setselectedClassTarget("link") //"link" or "linkparent"countries.init() </script></xsl:template><xsl:template match="tab[$tabIndex]"><xsl:apply-templates/></xsl:template><xsl:template match="tab"><li><a href="?tab={$tabIndex}" rel="#default"><xsl:if test="@name = $tab"><xsl:attribute name="class">selected</xsl:attribute><xsl:if><xsl:value-of select="mtitle" /></a></li></xsl:template></xsl:stylesheet>

Use PHP's XSL extension (and make sure you have it turned on!) with that XSLT and your XML. Make sure to also use XSLTProcessor::setParameter() with 'tabIndex' as name, and $_GET['tab'] as a value.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...