473,394 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Duplicate XSLT Output

I'm building a guitar website which uses XML and XSLT.
http://www.madtim67.com/guitar/index.html You can search either by artist or
song. I used the <xsl:if test="contains(artist ,$text1)"> line which worked
OK except now I get some duplicate output (go to the website and enter 'a'
to see what I mean. I included a unique id node in my xml file to make every
record unique. Is there a way that I can check the output the unique id
field only once.

Heres my XSL page

<?xml version="1.0"?>

<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>

<xsl:param name="text1" />

<xsl:template match="/">

<html>

<head>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
<title>Results</title>
</head>

<body>

<table class="three" align="center">

<col width="35%"/>
<col width="35%"/>
<col width="15%"/>
<col width="15%"/>

<tr>
<th class="head">Artist</th>
<th class="head">Song</th>
<th class="head">Chord</th>
<th class="head">Midi</th>
</tr>

<xsl:for-each select="cat/links[contains(artist,$text1)]">

<tr>
<td><xsl:apply-templates select="./artist"/></td>
<td><xsl:apply-templates select="./song"/></td>
<xsl:variable name="link1"><xsl:apply-templates
select="./chord"/></xsl:variable>
<td><a href="{$link1}" target="_blank">view</a></td>
<xsl:variable name="link2"><xsl:apply-templates
select="./midi"/></xsl:variable>
<td><a href="{$link2}" target="_blank">play</a></td>
</tr>

</xsl:for-each>

<xsl:for-each select="cat/links[contains(song,$text1)]">

<tr>
<td><xsl:apply-templates select="./artist"/></td>
<td><xsl:apply-templates select="./song"/></td>
<xsl:variable name="link1"><xsl:apply-templates
select="./chord"/></xsl:variable>
<td><a href="{$link1}" target="_blank">view</a></td>
<xsl:variable name="link2"><xsl:apply-templates
select="./midi"/></xsl:variable>
<td><a href="{$link2}" target="_blank">play</a></td>
</tr>

</xsl:for-each>

</table>

<div align="center">
<a href="javascript:history.go(-1)">Click here to return to search page</a>
</div>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

Heres my XML file

<cat>
<links>
<id>00001</id>
<artist>gerry rafferty</artist>
<song>baker street</song>
<chord>media/gerry_rafferty_-_baker_street.txt</chord>
<midi>media/gerry_rafferty_-_baker_street.mid</midi>
</links>
<links>
<id>00002</id>
<artist>men at work</artist>
<song>down under</song>
<chord>media/men_at_work_-_down_under.txt</chord>
<midi>media/men_at_work_-_down_under.mid</midi>
</links>
<links>
<id>00003</id>
<artist>squeeze</artist>
<song>up the junction</song>
<chord>media/squeeze_-_up_the_junction.txt</chord>
<midi>media/squeeze_-_up_the_junction.mid</midi>
</links>
<links>
<id>00004</id>
<artist>steve harley</artist>
<song>make me smile</song>
<chord>media/steve_harley_-_make_me_smile.txt</chord>
<midi>media/steve_harley_-_make_me_smile.mid</midi>
</links>
</cat>
Jul 20 '05 #1
1 1461
thomas wrote:
I'm building a guitar website which uses XML and XSLT.
http://www.madtim67.com/guitar/index.html You can search either by artist or
song. I used the <xsl:if test="contains(artist ,$text1)"> line which worked
OK except now I get some duplicate output (go to the website and enter 'a'
to see what I mean. I included a unique id node in my xml file to make every
record unique. Is there a way that I can check the output the unique id
field only once.
[...]
<xsl:for-each select="cat/links[contains(artist,$text1)]">
[...]
<xsl:for-each select="cat/links[contains(song,$text1)]">
[...]


Try

<xsl:apply-templates
select="cat/links[contains(artist,$text1)]|cat/links[contains(song,$text1)]/">

instead of that duplicate "xsl:for-each" elements.

Then, any element "cat/links[...]" should be matched just one time using

<xsl:template
match="cat/links[contains(artist,$text1)]|cat/links[contains(song,$text1)]">
<tr>......................</tr>
</xsl:template>

--
HTH
Volkm@r
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a...
1
by: Wolfgang | last post by:
XSLT transformations by default seem to pass name space attributes into the root element of their output (example below). QUESTION: Is it possible to control this, i.e. not genrating a name...
1
by: Lisa | last post by:
I need to apply the HTML formatting tags and the French accented characters in a XML document. The XML is generated from a database that has HTML tags and French accented characters in the records....
2
by: Taare | last post by:
Hi, I got <xsl:output method="html" encoding="iso-8859-1" doctype-public="-//W3C//DTD HTML 4.01//EN" doctype-system=" http://www.w3.org/TR/html4/strict.dtd"/> in my XSLT file. This should remove...
3
by: danmc91 | last post by:
Hi, I'm just getting going with xml and xslt. I'm trying to write what are essentially man pages and I need 3 output formats. 1) nroff -man format for real man pages 2) html for an online...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
18
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to...
1
by: tosachinji | last post by:
Hi I am new to xslt. Could you please tell me, how can we remove duplicate records from a xml file. Here is the xml file: <Row> <Cell><Data>Active</Data></Cell> <Cell><Data>D</Data></Cell>...
2
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.