I wanted to find all caption titles that contain the word "broken", regardless of the level of nesting.
Now I think the below code does the job. But how would I adapt this so the user can enter any search term and it will bring back the caption title if the word is matched in the index.xml file?
<results>
{
for $i in document("index.xml")//title[contains(./captiontitle(),"broken")]
Subject:search in XQuery Author:Minollo I. Date:02 Apr 2006 10:03 PM
You can create an external variable and bind it through the API consistent with the processing engine you are using.
You could change your test into:
declare variable $text external;
<results>
{
for $i in doc("c:\books.xml")//title[contains(captiontitle,$text)]
return $i
}
</results>
(btw, document() doesn't exist in XQuery/XPath, and "captiontitle" is not a function)
In Stylus Studio you can click XQuery > Scenario Properties, choose the "Parameter Values" tab, and enter something like "broken" (don't forget double or single quotes).
If you want to see the code required to do that, make sure you choose DataDirect XQuery or Saxon as your XQuery processor, select XQuery > Generate Java Code and you will see the code you need to bind external variables.
Subject:search in XQuery Author:TL W Date:03 Apr 2006 05:24 AM
Thanks Minollo.
Ive actually now figured out to implement a search function so a user can enter a search term and if you enter something that matches the “thumbsnavtitle” it will bring back the image etc.
Only problem is it doesn’t bring back any result, heres the code:
After finding something that potentially works I have now read that using scripting inside the XSLT has been deemed a security risk http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/xmlsdk/html/ba3e4d4f-1ee7-4226-a51a-78a1f1b5bd8a.asp
Subject:search in XQuery Author:Minollo I. Date:03 Apr 2006 08:50 AM
Are you asking an XSLT question? Are you asking how to do that in XQuery? Yes, XSLT purists won't like Java(Script) extensions; and it does seem to be useless to use them in your case.
As we usually write when questions are general language questions, we suggest that you post them on the xsl-list at mulberrytech.com, or on http://www.xquery.com/ for XQuery.