Jump to content

Running Php And Xml


Recommended Posts

I'm not sure if this should be in the PHP section, or the XML section. I'll try this section first...Okay, I am creating a website for my company that is selling trailers. I am using PHP for the site. However, I am keeping my trailer specification info in a XML file.I have successfully created an inventory page in PHP with XML and XSLT loaded in it. It show's a thumbnail picture of each trailer and the size and price. Then, I want to be able to click on one of the trailers and have it load a new page using PHP to show all of the stats on that particular trailer. I can get it to load a piece of the XML info into the address (eg. www.justanexample.com/page.php?vin=1000). So what do I do with that new page to load all the info for the trailer with that particular VIN number?here is an example of the XML file:

<stock>	<trailer>		<vin>1000</vin>		<make>Sample</make>		<model>Sample</model>		<length>Sample</length>		<width>Sample</width>		<color>Sample</color>		<add>Sample</add>		<price>Sample</price>		<src>/Sample.jpg</src>	</trailer></stock>

I have no idea how to show all of the info here from clicking on an image in a different page altogether.Any help would be greatly appreciated!

Link to comment
Share on other sites

You could have another stylesheet for those pages.Then, pass the GET variable as a parameter to XSLT. In XSLT, use the parameter's value to determine which trailor you must display. Something like this:

<xsl:stylesheet ...><xsl:param name="vin" /><xsl:template match="/">...<xsl:for-each select="//trailor[vin=$vin]"><xsl:value-of select="make"><xsl:value-of select="model">...</xsl:for-each>...</xsl:template></xsl:stylesheet>

In PHP, to pass the parameter, you can use XSLTProcessor::setParameter(), like so:

<?php$xsl = new DOMDocument;$xsl->load('details.xsl');$proc = new XSLTProcessor;$proc->importStyleSheet($xsl);//Here's the line$proc->setParameter(null, 'vin', $_GET['vin']);$xml = new DOMDocument;$xml->load('trailors.xml');echo $proc->transformToXML($xml);?>

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

  • Create New...