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?


Tried using something like this?

 <xsl:value-of select="$MyUrlVal" disable-output-escaping="yes" />
  • 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

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

<xsl:value-of select="substring-before(@URL, ', ')"/>
  • 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. – Eric Alexander 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. – Eric Alexander 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

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: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="','" />

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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