Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSLT site Search

Status
Not open for further replies.
Jan 26, 2001
550
GB
Hi guys,

I'm creating a search facility in xslt for my xml based site.

I pass the search terms to the xml by creating nodes called <searchterm> in the root of the xml. There can be any number of search terms.

I'm using the contains() function to search the xml for the terms provided. I have created the 'Search any word' and 'search exact phrase' options pretty easily, but i'm having trouble creating the 'search all words'(in any order).

I need to check all instances of //Root/Company/NewItem to see whether they contain all of the //Root/SearchTerm nodes. If a news item contains all of the search terms, in any order, i need to display it.

I can't figure out the logic to loop both the search terms and the news items, which would be pretty simple if only i could change the value of a variable as in asp.

Any suggestions would be greatly appreciated.

Thanks guys

I need to

Nick (Software Developer)


nick@retrographics.fsnet.co.uk
nick.price@myenable.com
 
have you investigated the possibility of using msxsl:script? i have been able to utilize many javascript functions, and other things by using this. an example would be

----------------------------------
<xsl:stylesheet
xmlns:xsl=&quot; version=&quot;1.1&quot;
xmlns:msxsl=&quot;urn:schemas-microsoft-com:xslt&quot;
xmlns:user=&quot;>
<xsl:template match=&quot;item&quot;>
<xsl:value-of select=&quot;user:format_item(string(@val))&quot;/>
</xsl:template>

<msxsl:script language=&quot;JScript&quot; implements-prefix=&quot;user&quot;>
function format_item(item) {
return StrReplace(item, &quot;'&quot;, &quot;\\'&quot;);
}
function StrReplace(str1, str2, str3)
{
str1 = str1.split(str2).join(str3);
return str1;
}
</msxsl:script>
</xsl:stylesheet>
-----------------------------------------

i'm sure that you could use some javascript string functions (see for a few) to do full text searching

hope this helps! mike griffith
----------------------------
mgriffith@lauren.com
mdg12@po.cwru.edu
 
>> I can't figure out the logic to loop both the search
>> terms and the news items, which would be pretty simple
>> if only i could change the value of a variable as in
>> asp.

Check out usage of:

<xsl:variable ... >

Good luck
-pete
 
Thanks for the suggestions guys. I eventually solved this by performing the 'search all terms' using asp instead of xsl. That MSXSL looks pretty useful though Mike, I might look into using that for future applications!

Thanks guys,

Nick Nick (Software Developer)


nick@retrographics.fsnet.co.uk
nick.price@myenable.com
 
Nick I am looking for a solution just like this for my small project I am working on right now. I am a neophyte with xml and I learn best by example. Would it be possible to see how you came up with this solution?

I am an environmental scientist and I do the programming for our small company. I am creating an xml document to list our periodical information and I need to create a full text search. (Like you mentioned 'Search any word','search exact phrase' and 'search all words'(in any order)) to bring back a result set.

Your help would be greatly appreciated.

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top