1

I've got a list that makes use of the "Hyperlink or Picture" field. The list is used to hold URLs.

What I really want to do is to display those URLs, not the pretty descriptions for them.

I searched here for a solution and found http://msdn.microsoft.com/en-us/library/ff604024.aspx

Man, that looks like a lotta work to display a URL, when it's right there.

So, I am appealing to the SP community here, hoping and praying that somebody has a painless means of displaying the URL instead of the description. Does anybody got something?

1 Answer 1

4

Customization the Rendering of a Field on a List View using XSLT is preferable option here.

Solution

Note: the method described below represents one of the possible ways how it could be accomplished with XSLT, i.e.:

a)SharePoint Designer (SPD) is used for customization

b)XSLT text is embedded using Xsl property in XSLListViewWebPart

In SharePoint Designer (SPD) open view page in Designer Mode. Select list item in List View that have to be customized (Hyperlink field) and then click Customize Item as shown on picture below enter image description here

Switch to Code mode and find generated code for rendering hyperlink field:

<xsl:template name="FieldRef_Hyperlink_URL_body.Link" ddwrt:dvt_mode="body" match="FieldRef[(@Format='Hyperlink') and @Name='Link']" mode="URL_body" ddwrt:ghost="show" xmlns:ddwrt2="urn:frontpage:internal">
  <xsl:param name="thisNode" select="."/>
  <xsl:variable name="url" select="$thisNode/@*[name()=current()/@Name]" />
  <xsl:variable name="desc" select="$thisNode/@*[name()=concat(current()/@Name, '.desc')]" />
  <xsl:choose>
    <xsl:when test="$url=''">
      <xsl:if test="$desc=''">
        <xsl:value-of select="$desc"/>
      </xsl:if>
    </xsl:when>
    <xsl:otherwise>
      <a href="{$url}" >
        <xsl:choose>
          <xsl:when test="$desc=''">
            <xsl:value-of select="$url"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$desc"/>
          </xsl:otherwise>
        </xsl:choose>
      </a>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

Note:

a) In my case match attribute has following value: "FieldRef[(@Format='Hyperlink') and @Name='Link']", where Name corresponds to field internal name

b) By default for Hyperlink field if description value is empty, then url is displayed

So, if you need for force it to display url instead of description replace it with the following template:

<xsl:template name="FieldRef_Hyperlink_URL_body.Link"  match="FieldRef[(@Format='Hyperlink') and @Name='Link']" mode="URL_body" ddwrt:ghost="">
  <xsl:param name="thisNode" select="."/>
  <xsl:variable name="url" select="$thisNode/@*[name()=current()/@Name]" />
  <a href="{$url}" >
    <xsl:value-of select="$url"/>
  </a>
</xsl:template>

Result pageenter image description here

4
  • Thank you, vgrem. I'm accepting this as the solution and plan on making use of it. I bet we can both agree it's far from painless, though. Does Microsoft expect the typical SharePoint user to do this sort of stuff? I should think not. Maybe this is something they'll add in, what, SharePoint 2016? Ugh.
    – Alan M
    Feb 4, 2013 at 18:18
  • :-)I totally agree, it's far from painless. But customizing the rendering of field using XSLT is supposed to be the best option here, we only need SharePoint Designer (no-code solution)... Feb 4, 2013 at 20:17
  • 1
    @AlanM if you just leave the description blank, it will display the URL. isn't that enough? :) isn't that the most painless way to do it? also you can paste the same URL in both URL and description. But trying to force eliminate the description from URL is quite another matter, I think it is something what a typical SharePoint user wouldn't want to do at all... Honestly I think you're inventing problems from nowhere and then blaming SharePoint for that. no offense. Feb 13, 2013 at 11:06
  • Leaving the descriptions blank would work fabulously, were it for a new list. Unfortunately, this is for an existing list that has a lot of entries in it. Tried editing in Datasheet View, and you can indeed right-click on the field and pick Hyperlink > Edit Hyperlink and get to the split URL / Description menu to strip out the description. That does take a bit of the sting out of it.
    – Alan M
    Feb 15, 2013 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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