The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> XML Programming
|
Passing parameters
Discuss Passing parameters in the XML Programming forum on Dev Shed. Passing parameters XML Programming forum discussing XML and related technologies, including XUL and XSL. XML is a self-describing file format, designed for maximum compatibility between applications.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 16th, 2012, 01:46 PM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 11
Time spent in forums: 4 h 56 m 47 sec
Reputation Power: 0
|
|
|
Passing parameters
K, so this is an annoying problem, but some help would be appreciated. I'm writing an internal search engine for a site I'm working on. Basically, I have an XML file, and I have an XSL that passes parameters based on elements from that file to the search engine. The problem is, I can only get the search to work based on a single parameter.
The search form goes like this;
<form action="search_process.htm" method="get">
Enter Zip Code: <input type="text" name="ZipCode"/><br />
Sort by:
<select name="sort_by">
<option value="ages taught" onclick="useElement()">ages taught</option>
<option value="best reviewed" onclick="disableElement()">best reviewed</option>
<select><br/>
Starting From:
<select name="sort_from" id="starting_from">
<option value="5+">5+</option>
<option value="6+">6+</option>
<option value="7+">7+</option>
<option value="8+">8+</option>
</select><br/>
<input type="submit" value="submit"/>
</form>
And then the XSL extracts that zip code and displays a table of results;
<xsl:for-each select="list/instructor[zipcode=$ZipCode]">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="userrating"/></td>
<td><xsl:value-of select="zipcode"/></td>
<td><xsl:value-of select="ages"/></td>
</tr>
</xsl:for-each>
The only thing in this table that affects the search, though, is the zip code. Now I need to get the three other search items listed into this code. I've tried putting it a few ways, but I can't get it right. How do I insert them?
|

May 16th, 2012, 03:19 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
You can have multiple predicates like
Code:
list/instructor[name=$Name][userrating=$UserRating][zipcode=$ZipCode][ages=$Ages]
|

May 16th, 2012, 03:26 PM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 11
Time spent in forums: 4 h 56 m 47 sec
Reputation Power: 0
|
|
|
The table is returned with no information at all now. Do I need an xsl:sort or something? I'm really new to this.
EDIT: can predicates be conditional?
|

May 16th, 2012, 04:54 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
- The sorting is separate, but yes I think you'll want that at some point.
- As I know it no, predicates cannot be conditional. But you can put two conditions ORed together into one, like
Code:
[$Name='' or name=$Name]
- What do you have now? Hopefully the whole thing?
|

May 17th, 2012, 11:39 AM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 11
Time spent in forums: 4 h 56 m 47 sec
Reputation Power: 0
|
|
|
I have the whole thing, yeah; there's the XML, XSL, HTML search page itself, and then a separate document with a long-*** script for removing XSL elements that don't match up with the user input.
The problem is, one search function is "Ages Taught", for the <ages> XML tag. But since the predicate dictates that ages=$sort_from, the table returns only those that match up EXACTLY with the users input, and I need it to list those that go above that value as well. If I can't write ages<=$sort_from, or even ages>=$sort_from, I'm afraid it'll get messy.
Your ORed solution sounds interesting, though; what exactly does that do?
|

May 17th, 2012, 12:05 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
An easy change would be in the form: make the age strictly numeric. No plus.
Code:
<option value="5">5+</option>
The ORed thing makes fields optional. The value is true if the field was empty or if it matches what's in the XML.
|

May 17th, 2012, 03:05 PM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 11
Time spent in forums: 4 h 56 m 47 sec
Reputation Power: 0
|
|
|
That's not changing anything, though; the table returned still only contains one result, the result that has both search criteria EXACTLY.
The result its giving me is the one with the input zipcode and the exact age input. But there's another result I want it to list here, which lists an age higher than the input.
As for ORed; it seems to merely reinforce the variable its paired with.
Is there anything else I could be doing wrong here?
|

May 17th, 2012, 04:11 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
What's your code?
|

May 23rd, 2012, 12:19 PM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 11
Time spent in forums: 4 h 56 m 47 sec
Reputation Power: 0
|
|
|
So it turns out your idea about removing the plus signs actually does work, but I didn't remove them from the XML. So I did that, and all is groovy now.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|