tags:

views:

730

answers:

4

I have a page which has URL structure : http://www.abc.com/xyz?parama=1&paramb=2

  • Is is possible to create a generic method for getting the values of any additional params the URL maybe (parama=1&paramb=2)

  • Is is possible to get the URL of the page in XSL similar to javascript's location.href ?

+2  A: 

This might be possible using EXSLT, or registering a function callback with your particular xslt processor, but not with plain old XSLT, at least not to my knowledge. With plain XSLT, if it isn't in the XML, then it doesn't exist.

Jordan S. Jones
A: 

If it is client side, there isn't any way of doing this. Unfortunately, xsl is very limited in the browser. I'm afraid you will need to move the functionality to the webapp or to javascript.

If the transform is server side, there might be something you can do.

Buddy
Could you elaborate how it can be done server-side?
Iris
@Iris, I'm afraid I can't, I've only done browser side xslt. Sorry.
Buddy
+2  A: 
Dimitre Novatchev
The paramas for the URL are being passed dynamically to the URL. How can I read the dynamic params and to parse them as you noted above ?
Iris
THe ways to pass a global parameter to an XSLT stylesheet are implementation-dependent and are described as part of each implementation of XSLT. For example, in .NET a global parameter is specified using the AddParam() method of the XsltArgumentList class.Using MSXML, it is necessary to use the AddParameter() object of the IXSLProcessor class. Yet in other systems the way to specify and pass a global parameter to an XSLT stylesheet will be different.Once the global parameter is passed to the stylesheet, then the code in my answer will parse it as shown.
Dimitre Novatchev
A: 

Hi, I workaround this by using javascript in mi XSLT file. take a look.

on The XML I have a tag element named tag! yes, very original...

<tag url="http://www.demo.net/share.php?u=param1 />

Mi Sample transform

<div class="HelloDiv">
        <xsl:for-each select="tag">
          <a href="{@url}">
            This is my custom URL
          </a>
        </xsl:for-each>
</div>

Now inside the template of the transform, in going to load my custom value in Param1 in this case i'm going to use the document.title.. by using a jquery function.

 <script type="text/javascript">
      jQuery(function(){
        jQuery('div.HelloDiv a').each(function(){
          var parameter = jQuery(this).attr('href');
          parameter = currentUrl.replace('param1',escape(document.title));
          jQuery(this).attr('href',parameter);
        })
      });
  </script>
Juan Zamora M