473,505 Members | 14,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Search XML Node

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. At the moment my XSL page only returns a result if the exact string is
entered i.e I have to enter 'baker street' or 'gerry rafferty' in order to
get a result. I would appriciate it if anyone could tell me how to modify
the code below so that if I enter 'baker' or 'gerry' I would get a result.

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">
<xsl:if test="./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:if>
</xsl:for-each>

<xsl:for-each select="cat/links">
<xsl:if test="./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:if>
</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>
<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>
<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>
<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>
<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 1358

You could change
<xsl:if test="./artist = $text1">

to

<xsl:if test="contains(artist ,$text1)">

Note you never need to start an XPath with ./ also you don't really need
an xsl:if here

<xsl:for-each select="cat/links">
<xsl:if test="./artist = $text1">

can be written
<xsl:for-each select="cat/links[artist = $text1]">

which is often preferable as it means for example that position() just
numbers the nodes that you actually want to output, useful for
numbering, or making alternating couloured rows in tables etc.
David
Jul 20 '05 #2

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

Similar topics

0
4216
by: j | last post by:
Hi, Anyone out there with binary search tree experience. Working on a project due tomorrow and really stuck. We need a function that splits a binary tree into a bigger one and smaller one(for a...
4
9002
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
19
13542
by: RAJASEKHAR KONDABALA | last post by:
Hi, Does anybody know what the fastest way is to "search for a value in a singly-linked list from its tail" as oposed to its head? I am talking about a non-circular singly-linked list, i.e.,...
7
1930
by: Bonj | last post by:
In making a ternary search tree to identify as fast as possible the type of word passed in to the algorithm, for instance sp_help -> 1 (procedures), select -> 2 (keywords), sysobjects -> 3 (system...
4
12006
by: Alan T | last post by:
I want to search the whole tree of a root node if one node has a tag value is matched. I have added tree nodes into a tree view with tag value is assigned to each node. If I want to find out...
4
2157
by: BenCoo | last post by:
Hello, In a Binary Search Tree I get the error : Object must be of type String if I run the form only with the "Dim bstLidnummer As New BinarySearchTree" it works fine. Thanks for any...
2
3852
by: Chris | last post by:
I know this probably seems trivial, but I can't seem to find the bug in my alphabeta search implementation. I'm testing it with the game of tic-tac-toe. If the first player plays in a corner,...
1
2072
by: gihope | last post by:
Hi, I wonder if someone could help me. I'm trying to develop a search algorithm as I need an engine that can determine the shortest route between two locations based on the number of stops. I...
2
2590
by: Defected | last post by:
Hi, How i can implement a main function with this Binary Search Tree. thanks for help. is this code corrected ? #include<iostream>
36
5888
Ganon11
by: Ganon11 | last post by:
OK, first of all, thanks to everyone who helped me out with my Isomorphism problem - it finally works. Now, the other part of my homework I'm having trouble with is this: I don't want to post...
0
7216
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
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7303
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
7471
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...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.