Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP XML Using ASP 3 and XML. See also the XML category for more XML discussions not relating to ASP. NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP XML section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 19th, 2008, 09:45 AM
Authorized User
 
Join Date: Jun 2008
Location: , , .
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Split function using ASp *Urgent*

Hello, I have a problem. I want to search more than 1 word using asp and xpath.
Here is my code:

<%
dim My_String
Dim My_Array
My_String=request.form("txtSearch")

My_Array=split(My_String," ")
For Each item In My_Array
Response.Write("<br>" & item)
Next

%>

Here is my XML:
<form>
    <document>
        <desc_id>024/HRCS-SP/P/7/98</desc_id>
        <title>Travel Cost</title>
        <dates>7/7/1998</dates>
        <author>Mr. XYZ</author>
        <file_name>galela_ternate</file_name>
        <type>doc</type>
        <category>procedure</category>
        <status>validate</status>
        <year>2002</year>
    </document>
</form>

And here is my xpath in 1 file together with my ASP code:
path="form/document[contains(.,"+'& My_String & '+")]//*";

Before using split function, I just can search with 1 word.
But, I want to know how if I want to search more than 1 word , e.g: "black book"

It works if I use like this:
path="form/document[contains(.,'Black') or contains(.,'Book') ]//*";

But, the values inside there, were static. I mean, both of them could not be changed depend on the user.

So, I use a variable "My_String" that related with the textfield.

Thank you

Reply With Quote
  #2 (permalink)  
Old June 19th, 2008, 01:47 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Well, you SHOWED what worked, so...

All we need to do is convert
    "Black Book"
into
    contains(.,'Black') or contains(.,'Book')
right?

So:

<%
CONST C_prefix = "contains(.,'"
CONST C_midfix = "') or contains(.,'"
CONST C_suffix = "')"

Function CreateContainsList( fromStr )
    Dim temp, re
    ' the regexp ensures that multiple spaces become single spaces
    Set re = New RegExp
    re.Pattern = "\s+"
    re.Global
    ' so get an array of words via split...
    temp = Split( re.Replace( Trim(fromStr), " " ), " " )
    ' and make it into the contains list via join and helpers
    CreateContainsList = C_prefix & Join( temp, C_midfix ) & C_suffix
End Function
%>

Untested, off the top of my head. But give it a shot.
Reply With Quote
  #3 (permalink)  
Old June 19th, 2008, 01:48 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Oops...should be
   re.Global = True
Reply With Quote
  #4 (permalink)  
Old June 19th, 2008, 02:08 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Now tested and works like a charm.

Example code:
Code:
<%
CONST C_prefix = "contains(.,'"
CONST C_midfix = "') or contains(.,'"
CONST C_suffix = "')"

Function CreateContainsList( fromStr )
    Dim temp, re
    ' the regexp ensures that multiple spaces become single spaces
    Set re = New RegExp
    re.Pattern = "\s+"
    re.Global = True
    ' so get an array of words via split...
    temp = Split( re.Replace( Trim(fromStr), " " ), " " )
    ' and make it into the contains list via join and helpers
    CreateContainsList = C_prefix & Join( temp, C_midfix ) & C_suffix
End Function

demo = "   My    Little     Black Book     "

path = "form/document[" & CreateContainsList(demo) & " ]//*"

Response.Write "<pre>" & demo & "" & path & "</pre>"
%>
And the output was:
Code:
   My    Little     Black Book     
-----------------------------------------------------------------------
form/document[contains(.,'My') or contains(.,'Little') or contains(.,'Black') or contains(.,'Book') ]//*
Reply With Quote
  #5 (permalink)  
Old June 20th, 2008, 01:08 AM
Authorized User
 
Join Date: Jun 2008
Location: , , .
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

when I run in different file, it works. But when I add those code inside javascript, it does not work.

demo = " My Little Black Book "

how if I want to change the content of demo? I mean, I want to get the value from the value that the user has been typed. Maybe using :
request.form("txtSearch") ?

If I want to add those code inside javascript, I just add those code inside <% %> right?

And, can I type like this?

Code:
<script type="text/javascript">
...
<%
CONST C_prefix = "contains(.,'"
CONST C_midfix = "') or contains(.,'"
CONST C_suffix = "')"

Function CreateContainsList( fromStr )
    Dim temp, re

    Set re = New RegExp
    re.Pattern = "\s+"
    re.Global = True
 
    temp = Split( re.Replace( Trim(fromStr), " " ), " " )

    CreateContainsList = C_prefix & Join( temp, C_midfix ) & C_suffix
End Function

demo = request.form("txtSearch")

%>

path = "form/document[" & CreateContainsList(demo) & " ]//*"
...
</script>


I want to add the path inside the javascript.

Reply With Quote
  #6 (permalink)  
Old June 20th, 2008, 05:42 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Trivial...And you don't even need or want the document.write that you used in your post in the wrong forum (in the JSP forum).

[code]
<%
... as given ...

demo = request.form("txtSearch")
path = "form/document[" & CreateContainsList(demo) & " ]//*"
%>

<script language="JavaScript">
var path = "<%=path%>";
</script>

*********************

You didn't *ASK* for it, but you *COULD* do all of this in JavaScript code, without involving ASP, at all, if you intend to do the XPath query in JavaScript.

But I'm not at all clear you know what you are doing here. I quite frankly wonder why you are using JavaScript at all. Surely you really want to do the XPath query in the ASP code, no????
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
split function equivalent asmotritsky SQL Server 2000 4 January 5th, 2009 08:40 AM
using the split function jd_erd Access 2 May 7th, 2007 09:59 PM
split function MunishBhatia ASP.NET 2.0 Professional 4 May 1st, 2007 10:05 AM
using 'Split' function p_gauri7 Crystal Reports 0 March 11th, 2005 01:02 PM
Split function Beulah ASP.NET 1.0 and 1.1 Basics 1 September 12th, 2003 09:14 AM



All times are GMT -4. The time now is 11:21 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.