Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2003
    Location
    NYC
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Displaying different XML information through a URL variable, via PHP

    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:

    Code:
      <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:

    Code:
      <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.
    ~ Erich w/ an h

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    I have no idea about xml, and don't know if you can mix php with it. If you can, then you can use:

    PHP Code:
    select="year[@id='<?php echo $_GET['id']; ?>']/show">
    Which will return whatever the id is on here tour.php?id=2003

  • #3
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Hmm, istead of xslt, you may want to use the xml parser functions. You should be able to find them on php.net


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •