views:

130

answers:

3

How to obtain document library name from the URL cqwp. For example,

http:///sites/site1/DocLib/Forms/AllItems.aspx

I know there is substring function with xsl

<xsl:param name="DocLibName"> 
  select=substring(url) or whatever the code should be
</xsl:param>
A: 

Using the standard substring(string, int, int) function won't get you very far because I expect that the length of the document library name is unknown.

However, there are two functions that you can use in concert, substring-after(string, string) and substring-before(string, string). As long as your site names aren't "Forms", you can retrieve a partial string using substring-before([URL], "/Forms"). For the rest... it'll still be troublesome if you don't have immediate access to the site's name, but even removing that option it's still much easier than complex calculations in URL length. You'd basically have to continually perform substring-after([string], "/") until you pop off the last slash.

ccomet
Thanks ccomet. I will give it a try and I will post the final code. Thanks / Ria
Langoria
A: 

The following code will give you the name of your document library from the URL you posted (or from any view in your document library)

String pattern = ".*/(?<listStaticName>.+)/[^\\.]+\\.aspx";
Regex regex = new Regex(pattern);
MatchCollection matches = regex.Matches(DefaultViewUrl);
String listStaticName = matches[0].Groups["listStaticName"].ToString();

You can use the method described in this article to call .NET code from XSL

Hugo Migneron
Hugo, 1. Thanks for your help but a. Is this code for xsd? If yes, where do I put the code? b. If not then can you give me xsd code to find out document library name from the url (get the current document libray name, it doesnot have to get it from the url if there is another way)
Langoria
You can call .NET from from your xsl code. I edited my answer with a link. Why the downvote btw?
Hugo Migneron
A: 
  1. Some good Links.

http://msdn.microsoft.com/en-us/library/dd583143(office.11).aspx

  1. Add these two line

<xsl:variable name="DocLibName" select="substring-before(substring-after($PageUrl, '/Forms/'), '/')" />

<xsl:param name="PageUrl"/>

  1. set VIEWFLAG=1 (it should be in the properties windows)

  2. Find this line and modify if you want Filter the webpart list

<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />

Change it to following

<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[(@CustomerNo=$DocLibName)]"/>

You can use this to display

<xsl:value-of select="$DocLibName"> <br/>

<xsl:value-of select="$PageUrl"/><br/>

Langoria