Hi guys I have the following xslt which takes values from a search form that I created. This works brilliant but I have two slight problems which im hoping someone can help me with.
<!--Form field variables-->
<xsl:variable name="strtype" select="umbraco.library:RequestForm('ctl00$ctl00$ctl00$ContentPlaceHolderDefault$SearchForm_3$ddlTypes')"/>
<xsl:variable name="strlocation" select="umbraco.library:RequestForm('ctl00$ctl00$ctl00$ContentPlaceHolderDefault$SearchForm_3$ddlLocation')"/>
<xsl:variable name="strcapacity" select="umbraco.library:RequestForm('ctl00$ctl00$ctl00$ContentPlaceHolderDefault$SearchForm_3$ddlGuestCapacity')"/>
<xsl:variable name="strkeywords" select="Exslt.ExsltStrings:uppercase(umbraco.library:RequestForm('ctl00$ctl00$ctl00$ContentPlaceHolderDefault$KeywordForm_3$txtKeywords'))" />
<xsl:for-each select="$sectionNode[contains((FunctionTypes), $strtype) and ($strlocation = location) and ($strcapacity = capacity) and (not(normalize-space($strkeywords))) ] | $sectionNode[contains(Exslt.ExsltStrings:uppercase(pageKeywords), $strkeywords) and normalize-space($strkeywords)]">
My problem is the user has to select a value in four for a any result to appear. What I would like is too allow the user to just search on one condition for example if they only entered a value in location e.g liverpool and then searched the results would show every single result that is located in liverpool. As it stands now i have to put in a value for every option to get a search result back for liverpool.
My other prob is because i am dynamically generating the ddl it is generating the html as this = ctl00$ctl00$ctl00$ContentPlaceHolderDefault$SearchForm_3$ddlLocation however is there a better way to set an id on the element and target that in the xslt?
Hope this is clear and some may be able to help me.
I have tried the code that you have suggested but im still not getting results to display :( (it may be a mistake from me?). Just to make it clearer for you. The alias of my properties are as follows
The dropdown list has two attributes one called id and one called name and when the html is generated the name and id were getting rendered as ctl00$ctl00$ctl00$ContentPlaceHolderDefault$SearchForm3$ddlFunctionTypes but in the code file they are just set as ddlFunctionTypes. All the clientIDMode does is remove this ctl00$ctl00$ctl00$ContentPlaceHolderDefault$SearchForm3$ so when the html is rendered it is just id="ddlFunctionTypes".
All this now matches so i'm unsure why the search results xslt is not generating anything if the user selects any amount of options from the drop down list options.
The only time i get search results to appear is when i use the keywords search. Do you think i could be loosing the form values when the search button is selected?
Actually - I think it's because of some PostBack thing... the DropDownList probably does an Ajax POST which means the XSLT is never processed with values in the Form.
You can test that by writing the $strtype and $strlocation etc. variables directly out in the HTML...
I now have it working i think i made a mistake somewhere i wrote it all out again and i can now generate results.
Problem i have now is that i have 3 venues with the following info stored on the system.
name = venue1
location = Liverpool
type = weddings
capacity = 250
name = venue2
location = Wrexham
type = weddings
capacity = 500
name = venue3
location = Liverpool
type = weddings
capacity = 750
when i search by just location e.g Liverpool only venue 1 and venue 2 displays which is great. However, when i search by liverpool and type weddings all venues show. Is there a way to filter only out only the venues that match all cases? e.g if I search
location = liverpool
type = weddings
capacity = 250
only venue 1 should show, however if i search if i take away the capacity value and search venue 1 and three should show as they match two conditions.
Would this be an xsl:if test somewhere?
Sorry to keep going on and your feedback is very much appreciated :)
You can do that for sure - it's just a matter of filtering further down, e.g. to grab only the venues that match both type and location, you can do:
<!-- Combine $typeNodes with all nodes from $locationNodes that are also in the $typeNodes set -->
<xsl:for-each select="$typeNodes | $locationNodes[@id = $typeNodes/@id]">
...
</xsl:for-each>
Note that the order matters - so you'll need to decide which criteria takes precedence over the others.
Again apologies for getting back but i cant seem to work this one out (not for trying tho) and xslt has fried my brain for the day lol.
I have been thinking about the logic that i need and im just getting confused with what you have suggested (it doesnt take much when it comes to xslt lol)
if the user just selects liverpool as the location then i want every single venue located in liverpool to show in the results.
Next if the user selects liverpool as the location and wedding as the function type i want only the venues who are located in liverpool and host the function type wedding to show in the results. If the venue is located in liverpool but doesn't host weddings then i don't want it to show or if the venue does host weddings but is not located in liverpool then again i dont want it to show either.
Again if the user now selects all three values, liverpool as the location, weddings as the function type and upto 200 guests as the as the capacity all i want to display in the search results is venues who match all three conditions. so if a venue is located in liverpool and it does hold upto 200 guests but it doesnt hold the function type wedding then i dont want it to show in the results.
Now im not sure if im thinking about this logic right (probably due to my lack of knowledge in xslt) but what i was thinking that the following 7 possibilities need to be considered.
option 1
Action = user selects just the location
Result = fetch back everything that only matches the location specified
option 2
Action = user selects location and function type
Result = fetch back everything that only matches the location and function type specified
option 3
Action = user selects location and capacity
Result = fetch back everything that only matches the location and capacity specified
option 4
Action = user selects location, function type and capacity
Result = fetch back everything that only matches the location, function type and capacity specified
option 5
Action = user selects just the function type
Result = fetch back everything that only matches the function type specified
option 6
Action = user selects function type and capacity
Result = fetch back everything that only matches the function type and capacity specified
option 7
Action = user selects just the capacity
Result = fetch back everything that only matches the capacity specified
So if the following is used to grab only the venues that match both type and location specified how do i implement all the other tests? has each for each loop with all the code have to be duplicated for each possibility?
<!-- Combine $typeNodes with all nodes from $locationNodes that are also in the $typeNodes set -->
<xsl:for-each select="$typeNodes | $locationNodes[@id = $typeNodes/@id]">
...
</xsl:for-each>
sorry to go on, but i feel the clearer i can try to explain then it may help you understand my problem.
I've been trying to help Paul out on this one and struggling to allow results to be pulled back based on any combination of the drop down boxes. Could you possibly help please?
Would love to help out more - just been very busy with actual work :(
Quick answer to the above, though: No, you shouldn't have multiple for-each statements - you should end up with one set of nodes comprising the combined results.
(And I know that's the heart of the problem :-)
Basically: Collect nodes from each of the variables (as showed earlier) and then combine using the technique where you only select nodes from another set if their @id matches one in another.
Help with xslt search
Hi guys I have the following xslt which takes values from a search form that I created. This works brilliant but I have two slight problems which im hoping someone can help me with.
My problem is the user has to select a value in four for a any result to appear. What I would like is too allow the user to just search on one condition for example if they only entered a value in location e.g liverpool and then searched the results would show every single result that is located in liverpool. As it stands now i have to put in a value for every option to get a search result back for liverpool.
My other prob is because i am dynamically generating the ddl it is generating the html as this = ctl00$ctl00$ctl00$ContentPlaceHolderDefault$SearchForm_3$ddlLocation however is there a better way to set an id on the element and target that in the xslt?
Hope this is clear and some may be able to help me.
Thank you
Paul
Hi Paul,
You're doing the right kind of thinking, actually. I usually throw in an intermediate step for clarity:
With regards to the stupid .NET ids - isn't there a property somewhere that puts you in charge of the ID? Something like ClientID or HtmlId ?
I have hated those IDs since the dawn of time :-)
Let me know if it doesn't work!
/Chriztian
Hi Chriztian
Thanks for the reply matey I will give it a whirl tommorrow morning and let you know how it goes!
Once again you come up trumps with regards to xslt :)
Awesome
Thanks
Paul
Good morning chriztian,
I have tried the code that you have suggested but im still not getting results to display :( (it may be a mistake from me?). Just to make it clearer for you. The alias of my properties are as follows
cityTown(property) = strlocationNodes venueFunctionTypes(property) = strtypeNodes guestCapacity(property) = strcapacityNodes pageKeywords = strpageKeywordsNodes (poor naming conventions i know lol)
I have three venues set as the location liverpool and if i only select liverpool from the location ddl I have no results returned.
Sorry if ive missed something. I tried to pput contains in the capacity and location nodes as it didnt work without.
thanks
Ps you were right with the other problem it was clientidMode="static"
Paul
Hi Paul,
Okay - just to be sure - what does the ClientIDMode do? Do you get to set your own IDs?
The fieldnames you're referencing in the
RequestForm()
calls should match the generated name attributes on the form fields.../Chriztian
Hi
The dropdown list has two attributes one called id and one called name and when the html is generated the name and id were getting rendered as ctl00$ctl00$ctl00$ContentPlaceHolderDefault$SearchForm3$ddlFunctionTypes but in the code file they are just set as ddlFunctionTypes. All the clientIDMode does is remove this ctl00$ctl00$ctl00$ContentPlaceHolderDefault$SearchForm3$ so when the html is rendered it is just id="ddlFunctionTypes".
All this now matches so i'm unsure why the search results xslt is not generating anything if the user selects any amount of options from the drop down list options.
The only time i get search results to appear is when i use the keywords search. Do you think i could be loosing the form values when the search button is selected?
thanks
Paul
Hi Paul,
Actually - I think it's because of some PostBack thing... the DropDownList probably does an Ajax POST which means the XSLT is never processed with values in the Form.
You can test that by writing the
$strtype
and$strlocation
etc. variables directly out in the HTML.../Chriztian
Hi
Yeah you are right with this placed in the xslt, no html is generated so it looks like it is not being processed :(.
Cheers
Paul
Hi Chriztian,
I now have it working i think i made a mistake somewhere i wrote it all out again and i can now generate results.
Problem i have now is that i have 3 venues with the following info stored on the system.
name = venue1 location = Liverpool type = weddings capacity = 250
name = venue2 location = Wrexham type = weddings capacity = 500
name = venue3 location = Liverpool type = weddings capacity = 750
when i search by just location e.g Liverpool only venue 1 and venue 2 displays which is great. However, when i search by liverpool and type weddings all venues show. Is there a way to filter only out only the venues that match all cases? e.g if I search
location = liverpool type = weddings capacity = 250
only venue 1 should show, however if i search if i take away the capacity value and search venue 1 and three should show as they match two conditions.
Would this be an xsl:if test somewhere?
Sorry to keep going on and your feedback is very much appreciated :)
Thanks
Paul
Hi Paul,
No worries - I love to help out :-)
You can do that for sure - it's just a matter of filtering further down, e.g. to grab only the venues that match both type and location, you can do:
Note that the order matters - so you'll need to decide which criteria takes precedence over the others.
/Chriztian
Hi Chriztian
Brilliant!!! I shall give that a whirl and let you know how I do :)
Thanks
Paul
Hi Chriztian,
Again apologies for getting back but i cant seem to work this one out (not for trying tho) and xslt has fried my brain for the day lol.
I have been thinking about the logic that i need and im just getting confused with what you have suggested (it doesnt take much when it comes to xslt lol)
if the user just selects liverpool as the location then i want every single venue located in liverpool to show in the results.
Next if the user selects liverpool as the location and wedding as the function type i want only the venues who are located in liverpool and host the function type wedding to show in the results. If the venue is located in liverpool but doesn't host weddings then i don't want it to show or if the venue does host weddings but is not located in liverpool then again i dont want it to show either.
Again if the user now selects all three values, liverpool as the location, weddings as the function type and upto 200 guests as the as the capacity all i want to display in the search results is venues who match all three conditions. so if a venue is located in liverpool and it does hold upto 200 guests but it doesnt hold the function type wedding then i dont want it to show in the results.
Now im not sure if im thinking about this logic right (probably due to my lack of knowledge in xslt) but what i was thinking that the following 7 possibilities need to be considered.
option 1
Action = user selects just the location Result = fetch back everything that only matches the location specified
option 2
Action = user selects location and function type Result = fetch back everything that only matches the location and function type specified
option 3
Action = user selects location and capacity Result = fetch back everything that only matches the location and capacity specified
option 4
Action = user selects location, function type and capacity Result = fetch back everything that only matches the location, function type and capacity specified
option 5
Action = user selects just the function type Result = fetch back everything that only matches the function type specified
option 6
Action = user selects function type and capacity Result = fetch back everything that only matches the function type and capacity specified
option 7
Action = user selects just the capacity Result = fetch back everything that only matches the capacity specified
So if the following is used to grab only the venues that match both type and location specified how do i implement all the other tests? has each for each loop with all the code have to be duplicated for each possibility?
sorry to go on, but i feel the clearer i can try to explain then it may help you understand my problem.
Thanks mate
Have a good weekend
Paul
Hi chriztian,
I've been trying to help Paul out on this one and struggling to allow results to be pulled back based on any combination of the drop down boxes. Could you possibly help please?
Many thanks
Hi guys,
Would love to help out more - just been very busy with actual work :(
Quick answer to the above, though: No, you shouldn't have multiple for-each statements - you should end up with one set of nodes comprising the combined results. (And I know that's the heart of the problem :-)
Basically: Collect nodes from each of the variables (as showed earlier) and then combine using the technique where you only select nodes from another set if their @id matches one in another.
/Chriztian
Ok, based on the idea of checking whether node id's match in the sets, this will work:
Thanks, Rog
Cheers for the help boys!
I'm a happy man now! #DeStress for the time being ha
Paul
is working on a reply...