XSLT filtering based on attribute value

S

sp

hai

i am new to this XSTL and i am trying to write xslt that will filter
out the xml value based on Attribute Value. my xml looks like this


<catalog>
<cd>
<title year="1990">Empire Burlesque</title>
<artist>Bob Dylan</artist>
<price>10.90</price>
</cd>
<cd>
<title year="1995">Hide your heart</title>
<artist>Bonnie Tyler</artist>
<price>9.90</price>
</cd>
<cd>
<title year="1995">Greatest Hits</title>
<artist>Dolly Parton</artist>
<price>9.90</price>
</cd>
<cd>
<title year=1995>Still got the blues</title>
<artist>Gary Moore</artist>
<price>10.20</price>
</cd>
<cd>
<title year="1998">Eros</title>
<artist>Eros Ramazzotti</artist>
<price>9.90</price>
</cd>
<cd>
<title year="1998">One night only</title>
<artist>Bee Gees</artist>
<price>10.90</price>
</cd>
</catalog>

and output should look like

<cd>
<title year="1995">Hide your heart</title>
<artist>Bonnie Tyler</artist>
<price>9.90</price>
</cd>
<cd>
<title year="1995">Greatest Hits</title>
<artist>Dolly Parton</artist>
<price>9.90</price>
</cd>
<cd>
<title year=1995>Still got the blues</title>
<artist>Gary Moore</artist>
<price>10.20</price>
</cd>


i am trying to extract all the nodes based on the attribute value year
i am unabel to know how to proceed using xstl
i tried to use the procedure which used to filter based on the tag
value it didnt work

xsl i used to filter


<?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>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd/title[@year='1995']">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

can anyone help

thanks

praveen
 
M

Martin Honnen

sp wrote:

<xsl:for-each select="catalog/cd/title[@year='1995']">

You want
<xsl:for-each select="catalog/cd[title[@year = '1995']]">
that way you iterate over the cd elements while your code iterates over
the title elements.
 
S

sp

hey thanks

thats working fine

thanks
praveen

Martin said:
sp wrote:

<xsl:for-each select="catalog/cd/title[@year='1995']">

You want
<xsl:for-each select="catalog/cd[title[@year = '1995']]">
that way you iterate over the cd elements while your code iterates over
the title elements.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top