|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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. ![]() |
|
#3
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Displaying by attribute via XPath |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|