XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old November 21st, 2003, 05:23 PM
Erich w/ an h Erich w/ an h is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 1 Erich w/ an h User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Displaying by attribute via XPath

My XML file looks basicaly like this:

Code:
<tour>
  <year id="2001">
    <show id="20010507">
      <date>05/07/01 (A)</date>
      <artist>Tim Solo</artist>
      <location>
        <venue>The Wetlands</venue>
        <city>New York City</city>
        <state>NY</state>
      </location>
    </show>
  </year>
  <year id="2003">
    <show id="20030227" status="canceled">
      <date>02/27/03</date>
      <artist>Tim Solo (A)</artist>
      <location>
        <venue>32 Bleu</venue>
        <city>Colorado Springs</city>
        <state>CO</state>
      </location>
    </show>
    <show id="20030228" status="canceled">
      <date>02/28/03</date>
      <artist>Tim Solo (A)</artist>
      <location>
        <venue>Bluebird Theater</venue>
        <city>Denver</city>
        <state>CO</state>
      </location>
    </show>
    <show id="20030301" status="canceled">
      <date>03/01/03</date>
      <artist>Tim Solo (A)</artist>
      <location>
        <venue>Fox Theater</venue>
        <city>Boulder</city>
        <state>CO</state>
      </location>
    </show>
  </year>
</tour>


and this is what my XSL file basically looks like:

Code:
<xsl:template match="/tour/year[@id='2001']">
<html>
  <head>
    <title>Tour: <xsl:value-of select="@id" /></title>
    <LINK REL="stylesheet" HREF="../pps.css" TYPE="text/css" />
  </head>
  <body bgcolor="#000000">
    <table Border="1" bordercolor="#444444" align="center" width="98%">
      <thead>
        <tr>
          <th width="10%">Date</th>
          <th width="20%">Artist</th>
          <th width="60%">Venue</th>
          <th width="10%">Show Info</th>
        </tr>
        <tr>
          <td colspan="4">.</td>
        </tr>
      </thead>
      <tbody>
      <xsl:apply-templates />
      </tbody>
    </table>
    <br />
    <br />
  </body>
</html>
</xsl:template>

<xsl:template match="/tour/year/show">
        <tr>
          <td align="center"><xsl:value-of select="date" /></td>
          <td align="center"><xsl:value-of select="artist" /></td>
          <td align="center"><xsl:value-of select="location/venue" />: <xsl:value-of select="location/city" />, <xsl:value-of select="location/state" /></td>
          <td align="center">Info</td>
        </tr>
</xsl:template>


when i go to display this, it filters the proper content into the table, but then prints all the other content in the xml file as text outside the table. I want to be able to filter the information in the xsl file via attribute in the xml file to show up in the table and have all the other information not shown. Am I doing something wrong?

Any help is apprectiated, thanks

Last edited by Erich w/ an h : November 22nd, 2003 at 06:02 AM.

Reply With Quote
  #2  
Old November 25th, 2003, 06:00 PM
tsprings tsprings is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Seattle, WA
Posts: 55 tsprings User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 5
Dear Enrich:

Try using the following for your xsl file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Tour: <xsl:value-of select="/tour/year[@id='2001']/@id" /></title>
<LINK REL="stylesheet" HREF="../pps.css" TYPE="text/css" />
</head>
<body>
<table Border="1" bordercolor="#444444" align="center" width="98%">
<thead>
<tr>
<th width="10%">Date</th>
<th width="20%">Artist</th>
<th width="60%">Venue</th>
<th width="10%">Show Info</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="/tour/year[@id='2001']/show">
<tr>
<td align="center"><xsl:value-of select="date" /></td>
<td align="center"><xsl:value-of select="artist" /></td>
<td align="center"><xsl:value-of select="location/venue" />:
<xsl:value-of select="location/city" />,
<xsl:value-of select="location/state" /></td>
<td align="center">Info</td>
</tr>
</xsl:for-each>
</tbody>
</table>
<br />
<br />
</body>
</html>
</xsl:template>
</xsl:stylesheet>

There should be a way to get the template to only select 2001, but I couldn't figure it out quickly. Also the "." that you had included puts all the rest of the content in. So that was part of your problem where all the rest of your XML content was showing.

Hope this helps.

Reply With Quote
  #3  
Old November 25th, 2003, 08:54 PM
tsprings tsprings is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Seattle, WA
Posts: 55 tsprings User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 5
Update

Hello again Enrich. I was able to spend a little more time on your problem, and I have another (better) implementation for you:

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="/tour/year[@id='2001']">
<html>
      <head>
            <title>Tour: <xsl:value-of select="@id" /></title>
            <LINK REL="stylesheet" HREF="../pps.css" TYPE="text/css" />
      </head>
      <body>
             <table Border="1" bordercolor="#444444" align="center" width="98%">
                      <thead>
                              <tr>
                                   <th width="10%">Date</th>
                                   <th width="20%">Artist</th>
                                   <th width="60%">Venue</th>
                                   <th width="10%">Show Info</th>
                               </tr> 
                       </thead>
                       <tbody>
                              <xsl:for-each select="show">
                                  <tr>
                                    <td align="center"><xsl:value-of select="date" /></td>
                                    <td align="center"><xsl:value-of select="artist" /></td>
                                    <td align="center"><xsl:value-of select="location/venue" />: 
                                        <xsl:value-of select="location/city" />, 
                                        <xsl:value-of select="location/state" /></td>
                                    <td align="center">Info</td>
                                   </tr>
                               </xsl:for-each>
                        </tbody>
              </table>
              <br />
              <br />
       </body>
</html>
</xsl:template>

<xsl:template match="/tour/year[@id!='2001']">
  <!--do nothing-->
</xsl:template>
</xsl:stylesheet>


Check out W3 Schools for more information on XSLT and XML.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Displaying by attribute via XPath


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway