Some might say both these technologies come from Old Nick himself , but I’m afraid I’ll have to disagree right there. XSLT has always been one of my all time favourite technologies, it’s uses are endless and there are many places in SharePoint where it’s a definite bonus to know XSLT to a good level.
So I just wanted to give you an idea of how neat a technology XSLT is and how integrated into the SharePoint stack it is.
Recently I was working on a custom list view which needed some custom XSLT and on this page I needed to create a link to another custom listview page. Now the problem was that the URL of our test box was http://ourtest.url/sites/intranet whereas the production farm was http://ourproduction.url .This created an issue in that if we weren’t careful each time we deployed to production we’d have to change the URL in the XSLT manually.
So initially our XSLT looked thus:
<ul class="nav">
<li>
<a href="/sites/intranet/list/Forms/NotWon.aspx">Not Won</a>
</li>
<li>
<a href="/sites/intranet/list/Forms/Won.aspx">Won</a>
</li>
</ul>
Thankfully there is a simple solution to this issue and that’s to use one of the XSLT Parameters that SharePoint has thankfully provided for us.
XSLT Parameters are value handed to us from outside of the Style sheet in this case by SharePoint. If you navigate to 14/TEMPLATE/LAYOUTS/XSL you will see the OOTB XSLT files used by SharePoint and you’ll see one called mail.xsl. If you open that up you see a whole bunch of <xsl:param /> tags with difference names. About half way down you’ll see HttpVDir. This is really handy as it gives us the full URL of the current SPWeb item. Check out MSDN for full details (in a second). And this value is available to you in any custom XSL you care to write for your listviews. So in order to construct a URL that would update automatically when deployed to other farms, we simply changed the above XSLT to read as follows:
<ul class="nav">
<li>
<a href="{$HttpVDir}/sites/intranet/list/Forms/NotWon.aspx">Not Won</a>
</li>
<li>
<a href="{$HttpVDir}/sites/intranet/list/Forms/Won.aspx">Won</a>
</li>
</ul>
Notice the shortcut syntax in XSLT used with attributes where the node or variable or in this case parameter appears simply in curly braces. Parameters in XSLT are always preceded by a $ sign. Job done. Have a play around with some of the other parameters and you’ll be pleased that you did!
Cheers
Dave Mc






Leave a reply to davemcmahon81 Cancel reply