Concatenating onto a variable?
This is an open discussion with 5 replies, filed under XSLT.
Search
You’ll want to use recursion to do this. Write a named template that conditionally passes the count and previous url string to itself. To dynamically generate the param name to test, you can use the exsl dyn:evaluate function.
Let me know if you need more. Just not in a recursive mood right now.
I get what you mean, but each param is not actually named “param#” but instead they all have different names.
The above is just a stripped down example for simplicity’s sake. Sorry for the mixup.
OK, I figured out how to do it by using If-statements inside a variable—never knew you could do that…—but I have to have all the Ifs on one line otherwise it adds spaces between the the content added by the Ifs.
Is there anything I can do about this? It’s not too big of a deal, just a bit harder to maintain my code.
Make sure you wrap your content with <xsl:text>content</xsl:text>
to avoid any unwanted spaces.
You can concatenate the pieces directly in the with-param
if you like:
<xsl:with-param name="url"> <xsl:text>/entries</xsl:text> <xsl:if test="$url-param1 != ''"> <xsl:text>/param1:</xsl:text> <xsl:value-of select="$url-param1"/> </xsl:if> ... <xsl:text>/$/</xsl:text> </xsl:with-param>
Create an account or sign in to comment.
OK so I’m in a slightly unique position here. I’m building a search page that uses pagination and, obviously, I’d like to keep the URL parameters when I switch form page to page in the pagination scheme. Problem is, by default clicking the link removes all URL parameters.
But I have a solution. I just don’t know how exactly to implement it. Basically I figure I can add a variable to the URL I’m generating and have that variable be populated based on what parameters are available.
Here’s where I am so far:
The problem is I don’t know how to concatenate onto my URL based on a series of If-statements. How would this be done? This is just an example. In reality there are 10 URL parameters to test for.