views:

37

answers:

1

Hi,

I have an URL Structure like this:

 http://my.domain.com/generated.xml?param1=foo&param2=bar&xsl=path/to/my.xsl

The generated XML will be transformed using the given XSL Stylesheet. The two other parameters are integrated too like this:

<root>
  <params>
    <param name="param1">foo</param>
    <param name="param2">bar</param>
  </param>
  ...
</root>

Now I want to create with XSLT a link with a new URI that keeps the existing parameters and adds one or multiple new parameters like page=3 or sort=DESC. If the given parameter already exists, it should be replaced.

I'm not sure how to do this. How to pass multiple (optional) parameters to a template. How to merge two lists of parameters.

Any ideas?

Thanks ;)

A: 

Your goal, as I understand it, is to build a string like this: http://my.domain.com/generated.xml?param1=foo&amp;param2=bar&amp;page=3&amp;sort=DESC&amp;xsl=path/to/my.xsl Without repeating an parameters. So if a request came in like this http://my.domain.com/generated.xml?param1=foo&amp;sort=ASC&amp;xsl=path/to/my.xsl you wouldn't want to accidentally make the result like this http://my.domain.com/generated.xml?param1=foo&amp;sort=ASC&amp;page=3&amp;sort=DESC&amp;xsl=path/to/my.xsl. Is that right?

If that's the case I would define a variable for each parameter you need, assigning it the value from the URL if applicable and a default value otherwise. Something along these lines:

<xsl:variable name="sort">
  <xsl:choose>
    <xsl:when test="/root/params/param[name='sort']">
      <!-- Use the available parameter if it exists. -->
      <xsl:value-of select="/root/params/param[name='sort']/text()"/>
    </xsl:when>
    <xsl:otherwise>
      <!-- Use a default value when the parameter doesn't exist. -->
      <xsl:text>DESC</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:variable>

And when you're building your resulting URI you can just use $sort and not have to worry about whether it's been populated with a default value or by URL parameter.

Welbog