Can anyone tell me how I can search a field with a term eg:
Search Number of bedrooms with a value from a dropdown such as 2 and also search a price range such as 100000-200000 and show any nodes with price values in that range?
You can use XSLT search as a base: http://www.percipientstudios.com/xsltsearch/overview.aspx. You can use it to search specific document type properties. You will probably have to extend it to make a customized search with dropdowns like you want but this will have done a lot of the work for you.
The easy way to do it would be to have two field or drop-down lists for the start and end range values on your form. Then, add that to your criteria in XSLTsearch. This blog post will explain the XSLTsearch modification, which is very simple. http://blog.percipientstudios.com/2009/4/7/customizing-xsltsearch.aspx
The more difficult way would be to parse the search field and look for a dash (-) to split() out the two terms. But I don't think that's as helpful for users as then they'd never be able to search for a dash character.
What I want to do is pass the values to the serch macro via a user control. So I need to split the values out and then feed them into the xslt. I think I will need to first select all the nodes of type - propertyDetails and then compare this result with the search query string. noBedrooms = search string. I'm just more used to SQL than xslt so I keep banging my head against a brick wall!!
Hi dandrayne, I have had a look through this and I think where I am hitting a problem is that I want to be able to compare the sub nodes of propertylist to match the search critera for Number of bedrooms and minimum Price. This example compare the sub nodes of a categroy. Am I correct?
I'd need to see the xml/node structure that you're searching and the xslt you have so far, as I'm not sure of the distinction between a property list and a category subnode
I have a node of propertyList with subnodes that are propertyDetails so "proertList/propertyDetails". On the propertydetails node I have data [@alias = 'noBedroomsDetails'] and data [@alias = 'propertyPrice'].
I have tried many different versions of xsly so far and came across your one. I think this will work
<xsl:variablename="minrooms"> <xsl:choose> <xsl:whentest="umbraco.library:Request('minrooms') <= 0 or string(umbraco.library:Request('minrooms')) = '' or string(umbraco.library:Request('minrooms')) = 'NaN'">0</xsl:when> <xsl:otherwise> <xsl:value-ofselect="umbraco.library:Request('minrooms')"/> </xsl:otherwise> </xsl:choose> </xsl:variable>
All stored in Umbraco, my approach now is to fist find all matching sub nodes of property list and then filter them by Number of bedrooms and by price. Just working out how to do that! So far what I have is basic.
* You have a node of type "Property List" * Under this you have nodes of type "Property Details" * Under these you have properties e.g. no of bedrooms ("noBedroomsDetails")
So to do a search based on the value from a querystring (which I'm pretending is in a xsl:variable called "minrooms")
This is untested, but it looks about right. Although the above is a little long, it's because I don't know where the search is taking place, so I go right back up to the homepage, then I find a node of type "Property List", then iterate through the child nodes testing the properties as I go.
Thanks for this, getting somewhere now. How can I set a variable value in xslt for testing, ie hard code the value so that I can build the results without the query string for now?
You can use umbraco.library:Split to split the value at the comma, but why not make life easier for yourself and send two paramaters (maxprice and minprice)?
Umbraco Search
Can anyone tell me how I can search a field with a term eg:
Search Number of bedrooms with a value from a dropdown such as 2 and also search a price range such as 100000-200000 and show any nodes with price values in that range?
Thaks in advance
You can use XSLT search as a base: http://www.percipientstudios.com/xsltsearch/overview.aspx. You can use it to search specific document type properties. You will probably have to extend it to make a customized search with dropdowns like you want but this will have done a lot of the work for you.
Thaks, I have started with this. I am having a problem searching a range like 100000-200000
This would require a modification to XSLTsearch.
The easy way to do it would be to have two field or drop-down lists for the start and end range values on your form. Then, add that to your criteria in XSLTsearch. This blog post will explain the XSLTsearch modification, which is very simple. http://blog.percipientstudios.com/2009/4/7/customizing-xsltsearch.aspx
The more difficult way would be to parse the search field and look for a dash (-) to split() out the two terms. But I don't think that's as helpful for users as then they'd never be able to search for a dash character.
cheers,
doug.
Thanks for this. I can get xslt to search a type of node but how do I limit it to search just 2 fields, price and bedrooms?
thanks
Basically what I want to do is something like on this page http://www.haddenrankin.com/sell-with-us.aspx without the area field. Can you point me in the right direction please?
Hi Jake,
a filter like that is pretty easy to do in a user control, with the help of http://our.umbraco.org/wiki/how-tos/useful-helper-extension-methods-%28linq--null-safe-access%29. Lets say you have a node with all the properies for sale, each of them having a number of bedrooms and a price. In your user control you can do something like
Hi Jake
If you have a look at http://our.umbraco.org/forum/developers/xslt/6751-Search-based-on-dropdowns-using-XSLT?p=0 you'll see how I did the dropdown search on haddenrankin, or at least a small part of it. What in particular are you having trouble with?
Dan
What I want to do is pass the values to the serch macro via a user control. So I need to split the values out and then feed them into the xslt. I think I will need to first select all the nodes of type - propertyDetails and then compare this result with the search query string. noBedrooms = search string. I'm just more used to SQL than xslt so I keep banging my head against a brick wall!!
Hi dandrayne, I have had a look through this and I think where I am hitting a problem is that I want to be able to compare the sub nodes of propertylist to match the search critera for Number of bedrooms and minimum Price. This example compare the sub nodes of a categroy. Am I correct?
Hi Jake
I'd need to see the xml/node structure that you're searching and the xslt you have so far, as I'm not sure of the distinction between a property list and a category subnode
Dan
I have a node of propertyList with subnodes that are propertyDetails so "proertList/propertyDetails". On the propertydetails node I have data [@alias = 'noBedroomsDetails'] and data [@alias = 'propertyPrice'].
I have tried many different versions of xsly so far and came across your one. I think this will work
Yes the code above will grab the querystring value for "minrooms" without problem. In the code listed at http://our.umbraco.org/forum/developers/xslt/6751-Search-based-on-dropdowns-using-XSLT?p=0 I'm also checking for subnodes that contain the values.
Can you post a sample of the xml you are searching? Or are your properties stored in umbraco?
Dan
All stored in Umbraco, my approach now is to fist find all matching sub nodes of property list and then filter them by Number of bedrooms and by price. Just working out how to do that! So far what I have is basic.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
xmlns:ps="urn:percipientstudios-com:xslt"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<!-- GET CATEGORY QUERY STRING -->
<xsl:variable name="noBedroomsDetailsquery">
<xsl:value-of select="umbraco.library:RequestQueryString('search')" />
</xsl:variable>
<!-- GET noBedroomsDetails QUERY STRING -->
<xsl:variable name="propertyPricequery">
<xsl:value-of select="umbraco.library:RequestQueryString('search')" />
</xsl:variable>
<xsl:for-each select="$currentPage/ancestor-or-self::node//node [@nodeName ='Property List']/node">
<xsl:call-template name="displayResults" />
</xsl:for-each>
</xsl:template>
<xsl:template name="displayResults">
<div id="resultsDetails">
<table id="reultsDetailstbl" cellspacing="0">
<tr>
<td rowspan="3" class="imageCol">
<a href="{umbraco.library:NiceUrl(@id)}" class="">
<img src="{data [@alias ='propertyThumbnail']}" class="propertyThumbnail" alt="{@nodeName}"/>
</a>
</td>
<td class="titleList" colspan="2">
<h2>
<xsl:value-of select="data [@alias = 'propertyTypeTitle']"/>
</h2>
</td>
</tr>
<tr>
<td class="detailsList">
<ul id="resultsList" style="margin-left: 0; padding-left: 5px;">
<li>
from <xsl:value-of select="format-number(data[@alias = 'propertyPrice'],'£###,###')"/>
</li>
<li>
<xsl:value-of select="data [@alias = 'noBedroomsDetails']"/> Bedrooms
</li>
</ul>
</td>
<td class="detailsList">
<a href="{umbraco.library:NiceUrl(@id)}" class="">
<img src="/img/detailsBtn.gif" class="detailsBtn" alt="{@nodeName}"/>
</a>
</td>
</tr>
<tr>
<td class="shortDetails" colspan="2">
<xsl:value-of select="data [@alias = 'propertyDescShort']"/>
</td>
</tr>
</table>
<hr style="color: #f3f1ed; background-color:#f3f1ed; border:0px; height:2px; text-align: 'left'; width: '100%'"/>
</div>
</xsl:template>
</xsl:stylesheet>
ok so here's what we know:
* You have a node of type "Property List"
* Under this you have nodes of type "Property Details"
* Under these you have properties e.g. no of bedrooms ("noBedroomsDetails")
So to do a search based on the value from a querystring (which I'm pretending is in a xsl:variable called "minrooms")
This is untested, but it looks about right. Although the above is a little long, it's because I don't know where the search is taking place, so I go right back up to the homepage, then I find a node of type "Property List", then iterate through the child nodes testing the properties as I go.
Dan
Oops, "min rooms", not = rooms
Thanks for this, getting somewhere now. How can I set a variable value in xslt for testing, ie hard code the value so that I can build the results without the query string for now?
Instead of
Just do something like
But you can also just manually add the querystring to your page e.g. mypage.aspx?minrooms=2
Dan
Thanks, am now getting along well. I will post my final code for you to have a giggle at!
One more thing, what is the best way of sorting my query string of http://localhost:5001/results.aspx?search=0,2000000 into two variables? Can this be done in xslt?
You can use umbraco.library:Split to split the value at the comma, but why not make life easier for yourself and send two paramaters (maxprice and minprice)?
Dan
Hi, Thanks, ignore me I had brain fade. Thanks for all your help, I have voted you MVP
Here is the final code for a search string
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
xmlns:ps="urn:percipientstudios-com:xslt"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<!-- GET CATEGORY QUERY STRING -->
<xsl:variable name="noBedroomsDetailsquery">
<xsl:value-of select="umbraco.library:RequestQueryString('search')" />
</xsl:variable>
<!-- GET noBedroomsDetails QUERY STRING -->
<xsl:variable name="propertyPricequery">
<xsl:value-of select="umbraco.library:RequestQueryString('price')" />
</xsl:variable>
<xsl:for-each select="$currentPage/ancestor-or-self::node//node [@nodeName ='Property List']/node[@nodeTypeAlias='PropertyDetails' and string(./data[@alias='noBedroomsDetails']) >= $noBedroomsDetailsquery and string(./data[@alias='propertyPrice']) <= $propertyPricequery]">
<p><xsl:value-of select="$noBedroomsDetailsquery" /><xsl:value-of select="data [@alias = 'noBedroomsDetails']"/></p>
<xsl:call-template name="displayResults">
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="displayResults">
<div id="resultsDetails">
<table id="reultsDetailstbl" cellspacing="0">
<tr>
<td rowspan="3" class="imageCol">
<a href="{umbraco.library:NiceUrl(@id)}" class="">
<img src="{data [@alias ='propertyThumbnail']}" class="propertyThumbnail" alt="{@nodeName}"/>
</a>
</td>
<td class="titleList" colspan="2">
<h2>
<xsl:value-of select="data [@alias = 'propertyTypeTitle']"/>
</h2>
</td>
</tr>
<tr>
<td class="detailsList">
<ul id="resultsList" style="margin-left: 0; padding-left: 5px;">
<li>
from <xsl:value-of select="format-number(data[@alias = 'propertyPrice'],'£###,###')"/>
</li>
<li>
<xsl:value-of select="data [@alias = 'noBedroomsDetails']"/> Bedrooms
</li>
</ul>
</td>
<td class="detailsList">
<a href="{umbraco.library:NiceUrl(@id)}" class="">
<img src="/img/detailsBtn.gif" class="detailsBtn" alt="{@nodeName}"/>
</a>
</td>
</tr>
<tr>
<td class="shortDetails" colspan="2">
<xsl:value-of select="data [@alias = 'propertyDescShort']"/>
</td>
</tr>
</table>
<hr style="color: #f3f1ed; background-color:#f3f1ed; border:0px; height:2px; text-align: 'left'; width: '100%'"/>
</div>
</xsl:template>
</xsl:stylesheet>
Heh, cheers ^^
good luck!
is working on a reply...