Partilhar via


Howto: Convert a URL field into the two components of the URL (description and link)

When you create a field of type URL in SharePoint, users need to fill out two form fields: “Link” and “Description”. When the Data View Web Part requests this field value, it gets back the full String value as concatenated by SharePoint. In order to make any use out of this String at all, you need to break it apart. Here is how to do that.

First, browse out to your Links list (which you get by default when you create a SharePoint site), and add a new link and description.

Then...

1. Insert a Data View Web Part based on the links list
2. Drag the URL field into the Data View (depending on how you accomplished #1 above, this field may already be in your view and may already be formatted correctly, but just pretend it isn't for future reference)
3. Notice that the field value for your URL field says this: https://www.microsoft.com, Microsoft
4. So, what you want to do is select substrings of this string value.
5. For the Link part, you want to use this XSLT: <xsl:value-of select=“substring-before(@URL, ', ')“/>
6. For the Description part, you want to use this XSLT: <xsl:value-of select=“substring-after(@URL, ', ')“/>

Let me know if this makes sense.

-John

Comments

  • Anonymous
    May 04, 2004
    I posted my own article on this topic (see URL above) as I found I got this same issue when pasting a column of hyperlinks into the DataList view of a wss list. Some people might find this useful to fix this problem once and for all rather than needing the custom data view as you describe?
  • Anonymous
    May 05, 2004
    This is actually a different problem, but your blog entry is certainly informational.

    The howto I wrote is about what to do with that Link data AFTER you have performed your steps. Your blog is about getting link data into a wss list so that it behaves like a URL field is supposed to behave; mine is about how you display that data on a web page once you get it into the list.

    I hope that distinction is clear.

    -John