I wanted to get at the site name to use in a Data View Web Part’s (DVWP) filter. An example is where you have a site per project, with the project number being the site name and you want to based various filters on that value. To do this, you can set up a parameter within the DVWP based on the value of the IIS Server Variable "URL" and parse out the project number using XSL.
Here are the steps (you will be doing all of this within SharePoint Designer — I’ll assume that you know how to set up DVWPs already):
- Once you have your DVWP set up on your page, click on the Common Data View Tasks (the little > twiddle button in the upper right of the DWVP when you’ve highlighted it) and choose "Parameters…"
- Click the "New Parameter" button
- Give your parameter a name, and set the "Parameter Source" to "Server Variable"
- For "Server Variable Name", type the text value of the Server Variable. There’s no help here from Designer; you need to type the value exactly right or it won’t work. See the link below for your options. In this case, we’ll type "URL" (without the quotes). Click OK when you are finished.
- Now click on "Filter:". Under "Field Name", select the column that you’d like to filter on, the "Comparison" (in this case "Equals"), and choose the Parameter that you just created in the dropdown for "Value". Check the "Add XSLT Filtering" checkbox and click "Edit".
- Enter the XSL to trim the value that you want out of the URL. for example, if all of your projects are below http://servername/Projects/, then the XSL would look like [substring-after(substring-before($URL,’/default.aspx’), ‘/Projects/’)]
Now the filter that you wanted should be in place. XSL has its vagaries, so if you get an error at any step, use your old friend Ctrl-Z to step back and try again.
A full reference of the available IIS Server Variables is at this link:
Note: I previously blogged on this method referencing a post from Maarten Eekels, but there are many more options, as outlined in the link above.
If you found this post helpful, please consider visiting one or more of the advertisers on the page. Writing good, in depth blog posts takes time, and advertising revenue - though by no means large - helps to offset the effort.