2

I have a custom list which contains a column of Hyperlink or Picture and URL formatted as Hyperlink. I then have a Content Query Web part on a page that uses this list as the source (Show items from the following list) and have selected a custom item style.

When creating a new item the Link URL's address and description are both populated.

However, I'm having difficulty finding a way to pull the link description when working within ItemStyle.xsl. I've seen LinkToolTip referred to, but that doesn't seem to be returning anything:

<a href="{$SafeLinkUrl}" title="{@LinkToolTip}">
    More <xsl:value-of select="@LinkToolTip" />
</a>

Unfortunately I can't seem to find anything online that shows how to do this in ItemStyle.xsl - just programmatically within code/CAML/views, or they use set text for all links.

What am I missing?

3
  • 1
    James, are you using a content query web part (CQWP)? Also, are you using any custom columns? If so, then in the web part itself, you must define these columns under the CommonViewFields property and set their type. This article covers this: heathersolomon.com/blog/articles/CustomItemStyle.aspx
    – Alex C
    Commented Aug 24, 2011 at 17:17
  • 1
    Thanks @Alex, I thought I remembered to include how I'm pulling it in - question updated. I am using a CQWP. I am using custom columns, but (and I might be understanding you wrong - I want to stay away from having a Web part that needs to be imported in since this will display across a handful of pages) I'm not using a custom column to store the link name I want to use. I'd like to just use the description associated with the Link Url custom column. And I think that was an answer instead of a comment :) Commented Aug 24, 2011 at 18:19
  • 1
    I started going through the motions of trying this and it's showing me Field equal to Link Url. In the List Settings > Columns interface I don't see the Link Url's description listed (which I don't find surprising). Is this something that I can perhaps only access programmatically? Commented Aug 24, 2011 at 22:16

2 Answers 2

1

This is only a work-around, but as I fear it may be what I need to do if I'm only using the ItemStyle.xsl ...

I added a new text column to my custom list called Link Text.

I then updated the ItemStyle.xsl from the version in the original question to the following:

<a href="{$SafeLinkUrl}">
    <xsl:value-of select="@LinkText" />
</a>

Upon saving the ItemStyle.xsl file I was able to edit my content query Web part so that the new LinkText field under Presentation > Fields to display pulled from Link Text;.

My Web part is now correctly pulling that field's value into the Web part once output.

It feels like a hack, especially since we're already populating a description when we add a link URL, so I would hope there's a better way. I think what's important is that adding @LinkToolTip to the template in ItemStyle.xsl does not display a new field under Presentation > Fields to display, while others added like this do. (This field name is also used in the default item style.)

4
  • 1
    James, what I've done in the past is to open the page in SP Designer and insert a Data View Web Part. This shows the data source and your columns; if you drag the column into the document, that can help with referencing its column name. A lot of times, the issue is with how SharePoint names the columns internally. For example, "Primary Phone" becomes "PrimaryNumber" internally. The article I linked to provides a neat way of getting the actual column names. Often, with wrong names, SharePoint won't even throw any errors.
    – Alex C
    Commented Aug 25, 2011 at 6:35
  • 1
    I think the problem is that the link url is a single column, but has more than one property/value - msdn.microsoft.com/en-us/library/… . I did follow the article you linked to from the comment you posted on the question and noted the column result as a comment response. When I get into the office I'll try out your SP Designer suggestion though; I hadn't thought of trying one of the standard view Web parts - good idea. Commented Aug 25, 2011 at 12:36
  • 1
    I finally had time to try the SharePoint Designer trick and that's of no help. So I guess I'm sticking with the work-around for now. I don't want to accept that this can't be done, though, so I'm not going to accept this as the answer ... :D Thanks @Alex - I appreciate the suggestions. Commented Sep 1, 2011 at 14:51
  • 1
    You're welcome, @James. Sorry for not being of more help. I've had to come up with workarounds as well with SharePoint. I know something is possible but at some point you have to get it working and move on to the next task.
    – Alex C
    Commented Sep 2, 2011 at 16:59
1

I had almost the same problem, the simplest, shortest solution to show a link from a Hyperlink or Picture field in the CQWP that I've found is the following:

I have a list which contains two columns of interest for this example: Title and SiteURL. The SiteURL column is of type "Hyperlink or Picture".

When that column enters the ItemStyle.xsl the value looks like "http://url.of/link, Url title", so to make a link of if and display we need to get everything before the ',' and after the ',' and make a link of it.

This is my resulting template in ItemStyles.xsl, without any other modifications.

<xsl:template name="ThaBomb" match="Row[@Style='ThaBomb']" mode="itemstyle">
    <xsl:variable name="MySiteLink" select="substring-before(@SiteURL, ',')"/>
    <xsl:variable name="MySiteTitle" select="substring-after(@SiteURL, ',')"/>
    <a href="{$MySiteLink}">
        <xsl:value-of select="@Title"/>
    </a>
</xsl:template>

When that's done, I went to edit the CQWP on the page, under Presentation->Item style I selected my template "ThaBomb" instead of Default. Also under Presentation->Fields to display I found my column SiteURL empty, in there I linked it to the actual column name (from the list), which in my case is also SiteURL.

As for getting all the field names, I had to modify (and add to) the xsl from your link (http://www.heathersolomon.com/blog/articles/CustomItemStyle.aspx) like so:

<xsl:for-each select="@*">
    Field: <xsl:value-of select="local-name()"/> : <xsl:value-of select="."/><br/>
</xsl:for-each>

to get the names and also add the values (which I thought I needed).

I believe the properties will display one of these fields under "Fields to display" for any field referenced in the template, but not necessarily bind it correctly. Anyway, after bound. Just hit OK and that did it for me, although in SharePoint 2013.

Hope it helps. / Richard

Your Answer

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

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