Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have the following question:

I'm modifying the XSLT of the search, so it is represented differently etc etc .. in this occasion I also need to get a relative site collection url.

In managed property i found a property SPSiteUrl, but adding it to properties for the xslt didn't help, as i got an error "inconsistent use of schema" etc etc, so how with other words can I retrieve the site collection relative url?

Because else i cannot know the relative url anyhow ...

OR if i'm in search, and i have the direct url to an item, how can i then by javascript decide which is the part of site collection url?

Any suggestions?

share|improve this question

1 Answer 1

When I customize XSLT for list views and forms (either as XSL referenced in the List's schema, or as an *.ascx that I deploy to CONTROLTEMPLATES) I used the following pre-defined parameter. You just declare it.. and then use it.. it's actual value is supplied magically elsewhere (in main.xsl, I think)

 <xsl:param name="HttpVDir"/>

The above param declaration goes near the top of your stylesheet (between the xsl:stylesheet tags, usually preceding any specific xsl:template tags).

Then, if you put this within the context of an xsl:template, it will output the site collection URL:

 <xsl:value-of select="$HttpVDir" />
share|improve this answer
Microsoft's official list of XSLT Global Parameters can be found here: msdn.microsoft.com/en-us/library/ff806158(v=office.14).aspx –  bkwdesign Jan 3 '13 at 22:42
So, to further answer your question, I would formulate the XSLT to output a tiny javascript block that declares a single JS variable: var siteCollectionUrl = ... which you can then reference in your other javascript logic. –  bkwdesign Jan 3 '13 at 22:46
In my further experimentation just now, for XSL files that are referenced in list schema documents, you can dispense with the param declaration and skip right to using the second snippet above. I think this is because XSL files start with an include reference to main.xsl –  bkwdesign Jan 3 '13 at 23:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.