#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep 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?
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,181
    Rep Power
    9398
    You can have multiple predicates like
    Code:
    list/instructor[name=$Name][userrating=$UserRating][zipcode=$ZipCode][ages=$Ages]
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep 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?
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,181
    Rep Power
    9398
    - 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?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep 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&gt;=$sort_from, I'm afraid it'll get messy.

    Your ORed solution sounds interesting, though; what exactly does that do?
  10. #6
  11. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,181
    Rep Power
    9398
    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.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep 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?
  14. #8
  15. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,181
    Rep Power
    9398
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    11
    Rep 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.

IMN logo majestic logo threadwatch logo seochat tools logo