Skip to main content

SharePoint Escapades

Go Search
IT Urban Home
Susan's Blog
Silence
Susan's Favorite Things
  

SharePoint Escapades > Posts > Filter by Query String, Unless Query String is Empty
Jump to Category: All   SharePoint Foundation   MOSS 2007   WSS 3.0   SQL Server 2008
sue
Filter by Query String, Unless Query String is Empty
So, you want to filter by query string, but what if the query string is empty?
 
Here is an example where I've created a parameter called QueryLetter, and I want to see if my list Title @Title starts with the QueryLetter:
 
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[($QueryLetter!='' and  starts-with(@Title,$QueryLetter)) or ($QueryLetter='')]"/>
 
Without the section in blue above, my XSL would return no results if a query string is not present.
 
Now, I will also get no results if $QueryLetter is H and @Title starts with lower case h. I solve this by adding the translate function. I know my $QueryLetter is always upper case, because I've created it, therefore I only need translate applied to @Title. The following will make @Title all upper case:
 
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[($QueryLetter!='' and  starts-with(translate(@Title,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),$QueryLetter)) or ($QueryLetter='')]"/>
BodyFilter
Thanks
Geez I feel stupid.
Jim ESQL Server 2008 SP1 & CU210/15/2010 7:28 PM