Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I would like to know the best way to encode parameters (with a space or other unsafe characters) when passing these to another List.

With ddwrt:UrlEncode ?

<xsl:variable name="MyURL"
  select="concat('../../Lists/MyList/MyView.aspx?MyID=',@ID,'&amp;MyName=',ddwrt:UrlEncode(string(@Title)))" />

The question is how to read this value on the page ? This one fails :

<xsl:value-of select="$MyName" />
share|improve this question
add comment

2 Answers

You'll definitely need to URLEncode values passed in URLs somehow. In plain .Net code this is done using HttpUtility.UrlEncode(), but if the ddwrt namespace has an XSL function which does this (as you appear to have found), I would have thought that should be fine too.

Can you verify this function works, perhaps by calling it in a different context?

share|improve this answer
    
oops, I see that some code was missing in my question, please take a look again. The URLEncode function works correct. MyView.aspx?MyID=',@ID,'&amp;MyName=',ddwrt:UrlEncode(string(@Title)) is correctly converted to MyView.aspx?MyID=1&MyName=My+Long+Name+With+Spaces But I guess that the + signs cannot be handled by <xsl:value-of select="$MyName" /> ? –  Stef Feb 18 '10 at 17:22
    
Hmm I wouldn't expect the '+' sign to cause a problem. However the thing that I'm wondering about the XSL you've provided is where is the 'MyName' XSL variable coming from? In what I see you just have a 'MyUrl' variable. I see that 'MyName' is a querystring parameter within the string which is in the 'MyUrl' variable, but I see no actual XSL variable called 'MyName' - this would explain the error. Does that make sense? –  Chris O'Brien - MVP Feb 18 '10 at 21:46
    
The URLEncode function is on the first page. And when a button is clicked, you are forwarded to the URL (second page). On that second page I've added a MyName Parameter and a MyName xslt variable, so that's not the problem. The problem is the + signs I think. Because normally you encode spaces with %20 ? –  Stef Feb 18 '10 at 22:09
    
Spaces can be escaped with %20, or the issue avoided by replacing them with '+' which the function appears to do. I'm not sure I have the full picture of what you're trying to do, but as a suggestion for now, don't forget that whenever you URL encode something, you have to URL decode it on the receiving page. Do you have that somewhere? –  Chris O'Brien - MVP Feb 18 '10 at 22:31
    
I do not decode it, because there is no ddwrt:UrlDecode function. Maybe I'm gonna write a custom xsl replace function which replaces all unsafe characters. –  Stef Feb 19 '10 at 9:17
add comment
up vote 2 down vote accepted

I found out that there's no need to encode a parameter using ddwrt:UrlEncode.

So the code on the first page becomes:

1) Building the URL

<xsl:variable name="MyURL" select="concat('../../Lists/MyList/MyView.aspx?ID=',@ID,'&amp;MyName=', @Title)" />

2) Creating a hyperlink

<a onclick="GoToLink(this); return false;" target="_self">
  <xsl:attribute name="href">
    <xsl:value-of select="$MyURL" />
  </xsl:attribute>
  Click My Link
</a>

Code on second page is just:

<ParameterBindings>
 ...
    <ParameterBinding Name="MyName" Location="QueryString(MyName)" DefaultValue="-"/>
</ParameterBindings>

<xsl:stylesheet />
  <xsl:param name="MyName" />
...

MyName : '<xsl:value-of select="$MyName" />'
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.