filter data in table from xml file

Discussion in 'XML' started by Peter, Dec 28, 2007.

  1. Peter

    Peter Guest

    Hello,

    id like to filter the data in a table from a xml file. The XML code
    and the HTML you can see below.
    What I want is that you can only see the CD Catalog from the country
    USA
    I can't figur it out.

    Can anyone help me

    Thanks
    Peter


    XML code
    --------------------------------------------------------------------
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    - <!--
    Edited with XML Spy v2007 (http://www.altova.com)
    -->
    - <CATALOG>
    - <CD>
    <TITLE>Empire Burlesque</TITLE>
    <ARTIST>Bob Dylan</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Columbia</COMPANY>
    <PRICE>10.90</PRICE>
    <YEAR>1985</YEAR>
    </CD>
    - <CD>
    <TITLE>Hide your heart</TITLE>
    <ARTIST>Bonnie Tyler</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>CBS Records</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1988</YEAR>
    </CD>
    - <CD>
    <TITLE>Greatest Hits</TITLE>
    <ARTIST>Dolly Parton</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>RCA</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1982</YEAR>
    </CD>
    - <CD>
    <TITLE>Still got the blues</TITLE>
    <ARTIST>Gary Moore</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Virgin records</COMPANY>
    <PRICE>10.20</PRICE>
    <YEAR>1990</YEAR>
    </CD>
    - <CD>
    <TITLE>Eros</TITLE>
    <ARTIST>Eros Ramazzotti</ARTIST>
    <COUNTRY>EU</COUNTRY>
    <COMPANY>BMG</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1997</YEAR>
    </CD>
    - <CD>
    <TITLE>One night only</TITLE>
    <ARTIST>Bee Gees</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Polydor</COMPANY>
    <PRICE>10.90</PRICE>
    <YEAR>1998</YEAR>
    </CD>
    - <CD>
    <TITLE>Sylvias Mother</TITLE>
    <ARTIST>Dr.Hook</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>CBS</COMPANY>
    <PRICE>8.10</PRICE>
    <YEAR>1973</YEAR>
    </CD>
    - <CD>
    <TITLE>Maggie May</TITLE>
    <ARTIST>Rod Stewart</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Pickwick</COMPANY>
    <PRICE>8.50</PRICE>
    <YEAR>1990</YEAR>
    </CD>
    - <CD>
    <TITLE>Romanza</TITLE>
    <ARTIST>Andrea Bocelli</ARTIST>
    <COUNTRY>EU</COUNTRY>
    <COMPANY>Polydor</COMPANY>
    <PRICE>10.80</PRICE>
    <YEAR>1996</YEAR>
    </CD>
    - <CD>
    <TITLE>When a man loves a woman</TITLE>
    <ARTIST>Percy Sledge</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Atlantic</COMPANY>
    <PRICE>8.70</PRICE>
    <YEAR>1987</YEAR>
    </CD>
    - <CD>
    <TITLE>Black angel</TITLE>
    <ARTIST>Savage Rose</ARTIST>
    <COUNTRY>EU</COUNTRY>
    <COMPANY>Mega</COMPANY>
    <PRICE>10.90</PRICE>
    <YEAR>1995</YEAR>
    </CD>
    - <CD>
    <TITLE>1999 Grammy Nominees</TITLE>
    <ARTIST>Many</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Grammy</COMPANY>
    <PRICE>10.20</PRICE>
    <YEAR>1999</YEAR>
    </CD>
    - <CD>
    <TITLE>For the good times</TITLE>
    <ARTIST>Kenny Rogers</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Mucik Master</COMPANY>
    <PRICE>8.70</PRICE>
    <YEAR>1995</YEAR>
    </CD>
    - <CD>
    <TITLE>Big Willie style</TITLE>
    <ARTIST>Will Smith</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Columbia</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1997</YEAR>
    </CD>
    - <CD>
    <TITLE>Tupelo Honey</TITLE>
    <ARTIST>Van Morrison</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Polydor</COMPANY>
    <PRICE>8.20</PRICE>
    <YEAR>1971</YEAR>
    </CD>
    - <CD>
    <TITLE>Soulsville</TITLE>
    <ARTIST>Jorn Hoel</ARTIST>
    <COUNTRY>Norway</COUNTRY>
    <COMPANY>WEA</COMPANY>
    <PRICE>7.90</PRICE>
    <YEAR>1996</YEAR>
    </CD>
    - <CD>
    <TITLE>The very best of</TITLE>
    <ARTIST>Cat Stevens</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Island</COMPANY>
    <PRICE>8.90</PRICE>
    <YEAR>1990</YEAR>
    </CD>
    - <CD>
    <TITLE>Stop</TITLE>
    <ARTIST>Sam Brown</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>A and M</COMPANY>
    <PRICE>8.90</PRICE>
    <YEAR>1988</YEAR>
    </CD>
    - <CD>
    <TITLE>Bridge of Spies</TITLE>
    <ARTIST>T'Pau</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Siren</COMPANY>
    <PRICE>7.90</PRICE>
    <YEAR>1987</YEAR>
    </CD>
    - <CD>
    <TITLE>Private Dancer</TITLE>
    <ARTIST>Tina Turner</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Capitol</COMPANY>
    <PRICE>8.90</PRICE>
    <YEAR>1983</YEAR>
    </CD>
    - <CD>
    <TITLE>Midt om natten</TITLE>
    <ARTIST>Kim Larsen</ARTIST>
    <COUNTRY>EU</COUNTRY>
    <COMPANY>Medley</COMPANY>
    <PRICE>7.80</PRICE>
    <YEAR>1983</YEAR>
    </CD>
    - <CD>
    <TITLE>Pavarotti Gala Concert</TITLE>
    <ARTIST>Luciano Pavarotti</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>DECCA</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1991</YEAR>
    </CD>
    - <CD>
    <TITLE>The dock of the bay</TITLE>
    <ARTIST>Otis Redding</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Atlantic</COMPANY>
    <PRICE>7.90</PRICE>
    <YEAR>1987</YEAR>
    </CD>
    - <CD>
    <TITLE>Picture book</TITLE>
    <ARTIST>Simply Red</ARTIST>
    <COUNTRY>EU</COUNTRY>
    <COMPANY>Elektra</COMPANY>
    <PRICE>7.20</PRICE>
    <YEAR>1985</YEAR>
    </CD>
    - <CD>
    <TITLE>Red</TITLE>
    <ARTIST>The Communards</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>London</COMPANY>
    <PRICE>7.80</PRICE>
    <YEAR>1987</YEAR>
    </CD>
    - <CD>
    <TITLE>Unchain my heart</TITLE>
    <ARTIST>Joe Cocker</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>EMI</COMPANY>
    <PRICE>8.20</PRICE>
    <YEAR>1987</YEAR>
    </CD>
    </CATALOG>

    ----------------------------------------------------------------------------------

    HTML CODE
    --------------------------------------------------------------------------------



    <html>

    <head>
    <script type="text/javascript">
    function testclick(field)
    {
    var row=field.rowIndex;
    xmldso_list.recordset.absoluteposition=row;
    td_title.innerHTML=xmldso_list.recordset("TITLE");
    td_artist.innerHTML=xmldso_list.recordset("ARTIST");
    td_year.innerHTML=xmldso_list.recordset("YEAR");
    td_country.innerHTML=xmldso_list.recordset("COUNTRY");
    td_company.innerHTML=xmldso_list.recordset("COMPANY");
    td_price.innerHTML=xmldso_list.recordset("PRICE");
    }
    </script>
    </head>

    <body>
    <xml id="xmldso_list" src="cd_catalog.xml"></xml>

    <table border="1" bgcolor="yellow">
    <tr align="left"><th>Title: </th><td id="td_title"></td></tr>
    <tr align="left"><th>Artist: </th><td id="td_artist"></td></tr>
    <tr align="left"><th>Year: </th><td id="td_year"></td></tr>
    <tr align="left"><th>Country:</th><td id="td_country"></td></tr>
    <tr align="left"><th>Company:</th><td id="td_company"></td></tr>
    <tr align="left"><th>Price: </th><td id="td_price"></td></tr>
    </table>

    <p><b>Click on one of the CDs in the list:</b></p>

    <table datasrc="#xmldso_list" border="1">
    <thead>
    <tr align="left">
    <th>Title</th>
    <th>Artist</th>
    <th>Country</th>
    <th>Company</th>
    <th>Price</th>
    <th>Year</th>
    </tr>
    </thead>
    <tr align="left" onclick="testclick(this)">
    <td><div datafld="TITLE" /></td>
    <td><div datafld="ARTIST" /></td>
    <td><div datafld="COUNTRY" /></td>
    <td><div datafld="COMPANY" /></td>
    <td align="right"><div datafld="PRICE" /></td>
    <td><div datafld="YEAR" /></td>
    </tr>
    </table>

    </body>
    </html>
     
    Peter, Dec 28, 2007
    #1
    1. Advertising

  2. Peter

    Peter Flynn Guest

    Peter wrote:
    > Hello,
    >
    > id like to filter the data in a table from a xml file. The XML code
    > and the HTML you can see below.
    > What I want is that you can only see the CD Catalog from the country
    > USA
    > I can't figur it out.


    The XPath statement /CATALOG/CD[COUNTRY[.='USA']] will select the CD
    elements you require (7 of them).

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/


    > XML code
    > --------------------------------------------------------------------
    > <?xml version="1.0" encoding="ISO-8859-1" ?>
    > - <!--
    > Edited with XML Spy v2007 (http://www.altova.com)
    > -->
    > - <CATALOG>
    > - <CD>
    > <TITLE>Empire Burlesque</TITLE>
    > <ARTIST>Bob Dylan</ARTIST>
    > <COUNTRY>USA</COUNTRY>
    > <COMPANY>Columbia</COMPANY>
    > <PRICE>10.90</PRICE>
    > <YEAR>1985</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Hide your heart</TITLE>
    > <ARTIST>Bonnie Tyler</ARTIST>
    > <COUNTRY>UK</COUNTRY>
    > <COMPANY>CBS Records</COMPANY>
    > <PRICE>9.90</PRICE>
    > <YEAR>1988</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Greatest Hits</TITLE>
    > <ARTIST>Dolly Parton</ARTIST>
    > <COUNTRY>USA</COUNTRY>
    > <COMPANY>RCA</COMPANY>
    > <PRICE>9.90</PRICE>
    > <YEAR>1982</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Still got the blues</TITLE>
    > <ARTIST>Gary Moore</ARTIST>
    > <COUNTRY>UK</COUNTRY>
    > <COMPANY>Virgin records</COMPANY>
    > <PRICE>10.20</PRICE>
    > <YEAR>1990</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Eros</TITLE>
    > <ARTIST>Eros Ramazzotti</ARTIST>
    > <COUNTRY>EU</COUNTRY>
    > <COMPANY>BMG</COMPANY>
    > <PRICE>9.90</PRICE>
    > <YEAR>1997</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>One night only</TITLE>
    > <ARTIST>Bee Gees</ARTIST>
    > <COUNTRY>UK</COUNTRY>
    > <COMPANY>Polydor</COMPANY>
    > <PRICE>10.90</PRICE>
    > <YEAR>1998</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Sylvias Mother</TITLE>
    > <ARTIST>Dr.Hook</ARTIST>
    > <COUNTRY>UK</COUNTRY>
    > <COMPANY>CBS</COMPANY>
    > <PRICE>8.10</PRICE>
    > <YEAR>1973</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Maggie May</TITLE>
    > <ARTIST>Rod Stewart</ARTIST>
    > <COUNTRY>UK</COUNTRY>
    > <COMPANY>Pickwick</COMPANY>
    > <PRICE>8.50</PRICE>
    > <YEAR>1990</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Romanza</TITLE>
    > <ARTIST>Andrea Bocelli</ARTIST>
    > <COUNTRY>EU</COUNTRY>
    > <COMPANY>Polydor</COMPANY>
    > <PRICE>10.80</PRICE>
    > <YEAR>1996</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>When a man loves a woman</TITLE>
    > <ARTIST>Percy Sledge</ARTIST>
    > <COUNTRY>USA</COUNTRY>
    > <COMPANY>Atlantic</COMPANY>
    > <PRICE>8.70</PRICE>
    > <YEAR>1987</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Black angel</TITLE>
    > <ARTIST>Savage Rose</ARTIST>
    > <COUNTRY>EU</COUNTRY>
    > <COMPANY>Mega</COMPANY>
    > <PRICE>10.90</PRICE>
    > <YEAR>1995</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>1999 Grammy Nominees</TITLE>
    > <ARTIST>Many</ARTIST>
    > <COUNTRY>USA</COUNTRY>
    > <COMPANY>Grammy</COMPANY>
    > <PRICE>10.20</PRICE>
    > <YEAR>1999</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>For the good times</TITLE>
    > <ARTIST>Kenny Rogers</ARTIST>
    > <COUNTRY>UK</COUNTRY>
    > <COMPANY>Mucik Master</COMPANY>
    > <PRICE>8.70</PRICE>
    > <YEAR>1995</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Big Willie style</TITLE>
    > <ARTIST>Will Smith</ARTIST>
    > <COUNTRY>USA</COUNTRY>
    > <COMPANY>Columbia</COMPANY>
    > <PRICE>9.90</PRICE>
    > <YEAR>1997</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Tupelo Honey</TITLE>
    > <ARTIST>Van Morrison</ARTIST>
    > <COUNTRY>UK</COUNTRY>
    > <COMPANY>Polydor</COMPANY>
    > <PRICE>8.20</PRICE>
    > <YEAR>1971</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Soulsville</TITLE>
    > <ARTIST>Jorn Hoel</ARTIST>
    > <COUNTRY>Norway</COUNTRY>
    > <COMPANY>WEA</COMPANY>
    > <PRICE>7.90</PRICE>
    > <YEAR>1996</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>The very best of</TITLE>
    > <ARTIST>Cat Stevens</ARTIST>
    > <COUNTRY>UK</COUNTRY>
    > <COMPANY>Island</COMPANY>
    > <PRICE>8.90</PRICE>
    > <YEAR>1990</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Stop</TITLE>
    > <ARTIST>Sam Brown</ARTIST>
    > <COUNTRY>UK</COUNTRY>
    > <COMPANY>A and M</COMPANY>
    > <PRICE>8.90</PRICE>
    > <YEAR>1988</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Bridge of Spies</TITLE>
    > <ARTIST>T'Pau</ARTIST>
    > <COUNTRY>UK</COUNTRY>
    > <COMPANY>Siren</COMPANY>
    > <PRICE>7.90</PRICE>
    > <YEAR>1987</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Private Dancer</TITLE>
    > <ARTIST>Tina Turner</ARTIST>
    > <COUNTRY>UK</COUNTRY>
    > <COMPANY>Capitol</COMPANY>
    > <PRICE>8.90</PRICE>
    > <YEAR>1983</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Midt om natten</TITLE>
    > <ARTIST>Kim Larsen</ARTIST>
    > <COUNTRY>EU</COUNTRY>
    > <COMPANY>Medley</COMPANY>
    > <PRICE>7.80</PRICE>
    > <YEAR>1983</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Pavarotti Gala Concert</TITLE>
    > <ARTIST>Luciano Pavarotti</ARTIST>
    > <COUNTRY>UK</COUNTRY>
    > <COMPANY>DECCA</COMPANY>
    > <PRICE>9.90</PRICE>
    > <YEAR>1991</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>The dock of the bay</TITLE>
    > <ARTIST>Otis Redding</ARTIST>
    > <COUNTRY>USA</COUNTRY>
    > <COMPANY>Atlantic</COMPANY>
    > <PRICE>7.90</PRICE>
    > <YEAR>1987</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Picture book</TITLE>
    > <ARTIST>Simply Red</ARTIST>
    > <COUNTRY>EU</COUNTRY>
    > <COMPANY>Elektra</COMPANY>
    > <PRICE>7.20</PRICE>
    > <YEAR>1985</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Red</TITLE>
    > <ARTIST>The Communards</ARTIST>
    > <COUNTRY>UK</COUNTRY>
    > <COMPANY>London</COMPANY>
    > <PRICE>7.80</PRICE>
    > <YEAR>1987</YEAR>
    > </CD>
    > - <CD>
    > <TITLE>Unchain my heart</TITLE>
    > <ARTIST>Joe Cocker</ARTIST>
    > <COUNTRY>USA</COUNTRY>
    > <COMPANY>EMI</COMPANY>
    > <PRICE>8.20</PRICE>
    > <YEAR>1987</YEAR>
    > </CD>
    > </CATALOG>
    >
    > ----------------------------------------------------------------------------------
    >
    > HTML CODE
    > --------------------------------------------------------------------------------
    >
    >
    >
    > <html>
    >
    > <head>
    > <script type="text/javascript">
    > function testclick(field)
    > {
    > var row=field.rowIndex;
    > xmldso_list.recordset.absoluteposition=row;
    > td_title.innerHTML=xmldso_list.recordset("TITLE");
    > td_artist.innerHTML=xmldso_list.recordset("ARTIST");
    > td_year.innerHTML=xmldso_list.recordset("YEAR");
    > td_country.innerHTML=xmldso_list.recordset("COUNTRY");
    > td_company.innerHTML=xmldso_list.recordset("COMPANY");
    > td_price.innerHTML=xmldso_list.recordset("PRICE");
    > }
    > </script>
    > </head>
    >
    > <body>
    > <xml id="xmldso_list" src="cd_catalog.xml"></xml>
    >
    > <table border="1" bgcolor="yellow">
    > <tr align="left"><th>Title: </th><td id="td_title"></td></tr>
    > <tr align="left"><th>Artist: </th><td id="td_artist"></td></tr>
    > <tr align="left"><th>Year: </th><td id="td_year"></td></tr>
    > <tr align="left"><th>Country:</th><td id="td_country"></td></tr>
    > <tr align="left"><th>Company:</th><td id="td_company"></td></tr>
    > <tr align="left"><th>Price: </th><td id="td_price"></td></tr>
    > </table>
    >
    > <p><b>Click on one of the CDs in the list:</b></p>
    >
    > <table datasrc="#xmldso_list" border="1">
    > <thead>
    > <tr align="left">
    > <th>Title</th>
    > <th>Artist</th>
    > <th>Country</th>
    > <th>Company</th>
    > <th>Price</th>
    > <th>Year</th>
    > </tr>
    > </thead>
    > <tr align="left" onclick="testclick(this)">
    > <td><div datafld="TITLE" /></td>
    > <td><div datafld="ARTIST" /></td>
    > <td><div datafld="COUNTRY" /></td>
    > <td><div datafld="COMPANY" /></td>
    > <td align="right"><div datafld="PRICE" /></td>
    > <td><div datafld="YEAR" /></td>
    > </tr>
    > </table>
    >
    > </body>
    > </html>
     
    Peter Flynn, Dec 29, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mank
    Replies:
    3
    Views:
    1,214
    Malte
    Feb 17, 2005
  2. Rio
    Replies:
    4
    Views:
    1,245
  3. Luca
    Replies:
    10
    Views:
    686
    luca milan
    Dec 9, 2003
  4. zax75
    Replies:
    1
    Views:
    1,140
  5. Replies:
    5
    Views:
    109
    Chris Angelico
    May 14, 2014
Loading...

Share This Page