...

View Full Version : Displaying different XML information through a URL variable, via PHP



Erich
12-02-2003, 11:18 PM
If this is in the wrong forum, my apologies, i felt it would work best in PHP.

Ok, the final goal for my site is to be able to control what content from an XML file is shown on a page via PHP. Ive got the XML file and its coresponding XSLT file, with some aspects of it that i want to have as variables. example:



<year id="2001">
<show id="20010509">
<date id="05/09/01">
<month>May</month>
<day>09</day>
<year>2001</year>
</date>
<artist>Tim Solo (A)</artist>
<location>
<venue>The Stanhope House</venue>
<city>Stanhope</city>
<state>NJ</state>
</location>
</show>
</year>
<year id="2003">
<show id="20030227" status="canceled">
<date id="02/27/03">
<month>February</month>
<day>27</day>
<year>2003</year>
</date>
<artist>Tim Solo (A)</artist>
<location>
<venue>32 Bleu</venue>
<city>Colorado Springs</city>
<state>CO</state>
</location>
</show>


part of one particular xslt file:



<xsl:template match="tour">
<xsl:for-each select="year[@id='2003']/show">
<tr>
<td>
<xsl:value-of select="date/@id"/>
</td>
<td>
<xsl:value-of select="artist"/>
</td>
<td>
<xsl:value-of select="location/venue"/>: <xsl:value-of select="location/city"/>, <xsl:value-of select="location/state"/>
</td>
<td>Info</td>
</tr>
</xsl:for-each>
</xsl:template>


i want to be able to set id='2003' as a variable to be determined by the URL, like /tour.php?id=2003.

Now, I have very little knowledge of PHP. I dont like asking for answers to things i havent fiddled with completely, but I dont know where to start when it comes to even parsing the XML. Any help would be appriciated.

Nightfire
12-02-2003, 11:40 PM
I have no idea about xml, and don't know if you can mix php with it. If you can, then you can use:



select="year[@id='<?php echo $_GET['id']; ?>']/show">


Which will return whatever the id is on here tour.php?id=2003

bcarl314
12-03-2003, 06:14 PM
Hmm, istead of xslt, you may want to use the xml parser functions. You should be able to find them on php.net



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum