Describe how to get the URL in XSL?

I ran into a little issue when I had two DataFormWebParts in a page, and I needed to get the current URL for one of them. In my 2nd DFWP, I had the parameters like "PageUrl", "HttpHost" available, but my 1st DFWP that was not the case. Now, in other languages like JavaScript, ASP.NET, etc., this is a relatively simplistic thing to get, but in XSL there's not like a <xsl:servervariable name="HTTP_HOST" />, although it would be great if there were support like that. :)

So, here's what I did.

  1. Create two new binding parameters
    <ParameterBinding Name="url_PATH_INFO" Location="ServerVariable(PATH_INFO)" DefaultValue=""/>
    <ParameterBinding Name="url_HTTP_HOST" Location="ServerVariable(HTTP_HOST)" DefaultValue=""/>


  2. After the start of the <xsl:stylesheet> tag, create matching xsl parameters.
    <xsl:param name="url_PATH_INFO" />
    <xsl:param name="url_HTTP_HOST" />


  3. Finally, create an <xsl:variable> concating the parameters togeter.
    <xsl:variable name="CurrentPageUrl" select="concat('http://',$url_HTTP_HOST,$url_PATH_INFO)" />

No comments:

Post a Comment