Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Duplicate XSLT Output

Reply
Thread Tools

Duplicate XSLT Output

 
 
thomas
Guest
Posts: n/a
 
      05-03-2005
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"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="html"/>

<xslaram 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>


 
Reply With Quote
 
 
 
 
Volkm@r
Guest
Posts: n/a
 
      05-04-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl Format the Output in table,by removing duplicate entries ppnair Perl Misc 0 10-11-2012 12:43 PM
need help with XSLT displaying multiple (duplicate) nodes Mad Scientist Jr XML 1 07-19-2007 11:53 PM
ANN: New low-cost XML Editor, XSLT Editor, XSLT Debugger, DTD/Schema Editor Stylus Studio Java 0 08-03-2004 03:53 PM
xslt alone or xslt/java for static site? ted XML 1 01-26-2004 10:41 AM
[XSLT]Passing values from Javascript to a XSLT variable Benjamin Hillsley XML 3 09-25-2003 04:50 AM



Advertisments