 |
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

June 17th, 2008, 07:34 AM
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Xpath problem
Hello,
I have a problem by using xpath.
Here is my Xpath:
path="form/document[contains(.,'<%= request.Form("txtSearch")%>')]//*";
If I run that code, I just can search only one word or the exact word.
For example, in my XML file, only available "black","board" and "white board"
If I type "black board" with that code, It shows nothing.
So, I want to know, how if I type "black board", the content of my XML file appear because the program will run the word with "black" + "board" + "black board".
Thanks
|

June 17th, 2008, 07:40 AM
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
XPath 2.0 supports regular expressions.
With XPath 1.0 you can use the boolean operators 'or' or 'and' e.g.
Code:
form/document[contains(., 'black') or contains(., 'board')]//*
So you will have to build such an XPath expression in your server-side code.
--
Martin Honnen
Microsoft MVP - XML
|

June 17th, 2008, 07:46 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Well, you can tokenize the input, search for each of the terms separately, and combine the results. But I don't think you can do this in a single XPath expression, even with XPath 2.0.
You're becoming more ambitious, but I don't think you have a clear view of the road ahead. It would be a good idea to read something about free-text retrieval systems (for example the XQuery/XPath full text specification at http://www.w3.org/TR/xquery-full-text/) and decide how far you want to go down the road to implementing fully-featured text retrieval. Alternatively, you might consider implementing a software package that does the job well, rather than doing it in a half-hearted way "by hand".
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|

June 17th, 2008, 07:56 AM
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It runs very well. Thanks a lot =)
But, if I change 'doc' and 'pdf' with the variable that I get when user type the word, it showed nothing=(
Here is what I mean:
path="form/document[contains(.,'<%= request.Form("txtSearch")%>') or contains(.,'<%= request.Form("txtSearch")%>')]//*";
It runs very well if I change like this:
path="form/document[contains(.,'pdf') or contains(.,'doc')]//*";
Help me please...
|

June 17th, 2008, 08:07 AM
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
Assuming you use VBScript and classic ASP on the server then you need to split Request.Form("txtSearch") with the proper VBScript code.
VBScript is documented here: http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx
--
Martin Honnen
Microsoft MVP - XML
|

June 17th, 2008, 09:50 AM
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello, I tried again and it works =)
Thanks a lot
:)
|

June 18th, 2008, 09:41 AM
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello, I was wrong...
When I tried :
path="form/document[contains(.,'<%= request.Form("txtSearch")%>')]//*";
It works well.
But when I tried this:
path="form/document[contains(.,'<%= request.Form("txtSearch")%>') and contains(.,' ') or contains(.,'<%= request.Form("txtSearch")%>')]//*";
It was also works well BUT it shows all the xml data. Not only "black" "board" or "black board" but also all xml data.
Help me please.
|

June 18th, 2008, 09:49 AM
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
Use VBScript string processing functions like Split to split Request.Form("txtSearch") and build up an XPath expression.
--
Martin Honnen
Microsoft MVP - XML
|

June 18th, 2008, 10:03 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I would have said your two expressions are equivalent
(A and B or A)
means exactly the same as
(A)
This is assuming there's nothing peculiar about
request.Form("txtSearch")
As has been said umpteen times on this thread, the debugging would be easier if you showed us the XPath expression you are executing, not the code that generates it.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|

June 18th, 2008, 11:15 AM
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
What do you mean by
Quote:
quote:As has been said umpteen times on this thread, the debugging would be easier if you showed us the XPath expression you are executing, not the code that generates it.
|
Show XPath expression that I'm executing?
And do you know the "split" code?
Can you show me the example / the code?
|
|
 |