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'm having some trouble with URL fields in my List. The problem is that SharePoint stores URLs in two parts, "Description" and "Url", but in SharePoint Designer I can only access the whole URL in the form of <Url>, <Description>. Splitting the string at ', ' is not complicated, but for some reason all Urls containing a ',' are escaped to ',, '.

So my url: http://example.com/myimage,cool.jpg
is rendered as: http://example.com/myimage,, cool.jpg, Description

Is there any elegant way to fix this (tried output escaping, but the ,, still remained) or do I have to go through some tedious xslt transformations?

share|improve this question
add comment

3 Answers 3

Tried using something like this?

 <xsl:value-of select="$MyUrlVal" disable-output-escaping="yes" />
share|improve this answer
    
Yep, didn't help: <img alt="myimage"> <xsl:attribute name="src"> <xsl:value-of select="@Myimage" disable-output-escaping="yes" /> </xsl:attribute> </img> –  Indrek Mar 14 '11 at 8:58
add comment

Use the xsl substring-before function, it isn't difficult.

<xsl:value-of select="substring-before(@URL, ', ')"/>
share|improve this answer
    
But when your value is literally http://server/myimage,,cool.jpg then that won't do much. –  James Love Mar 14 '11 at 13:54
    
That's an input validation issue since that isn't a valid URL to begin with. That should be addressed in a presave action perhaps. –  PirateEric Mar 14 '11 at 14:03
    
I just tested the above with a URL with a comma in it and it does work properly. It is looking for everything before comma space and returns that. SO if it were input as example.com/myimage,cool.jpg with a description of Why would you do this, it renders as example.com/myimage,cool.jpg in my DVWP. –  PirateEric Mar 14 '11 at 14:08
    
If I remember correctly, then the double commas were followed by a space and the file names contained multiple commas in different locations. Unfortunately, there's no way to run substring-before() on the last match. I'll check it in the morning. –  Indrek Mar 14 '11 at 21:18
add comment
up vote 0 down vote accepted

Here's how I got around the problem:
Used a similar XSLT function: http://geekswithblogs.net/Erik/archive/2008/04/01/120915.aspx and called it:

<xsl:variable name="imgEscapedTemp">
  <xsl:call-template name="string-replace-all">
    <xsl:with-param name="text" select="@Image" />
    <xsl:with-param name="replace" select="',,'" />
    <xsl:with-param name="by" select="'##'" />
  </xsl:call-template>
</xsl:variable>

<xsl:variable name="imgEscaped">
  <xsl:call-template name="string-replace-all">
    <xsl:with-param name="text" select="substring-before($imgEscapedTemp, ', ')" />
    <xsl:with-param name="replace" select="'##'" />
    <xsl:with-param name="by" select="','" />
  </xsl:call-template>
</xsl:variable>

<img src="{$imgEscaped}" alt=myImage" />

Logic: replace ',,' with '##', substring before ', ' and then replace '##' with ','

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.