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 posted this question on StackOverflow a couple of weeks ago, but since it hasn't got very much attention I'm posting it here instead.


I'm building a Content Query Web Part that is supposed to show a link to a user page (userdisp.aspx). I get the user name from a custom list containing a column named 'Member' of the type 'Person or Group'.

enter image description here

To build the link in the ItemStyle.xsl, I need both the name and the Id of the user:

<a href="http://<site>/_layouts/userdisp.aspx?ID=@ID">
    <xsl:value-of select="@Name" />
</a>

However, I'm only able to get the name OR the Id from the Content Query. E.g. if I set "Show field: Name (with presence)" for the Member column I get the name, and if I set "Show field: ID" I obviously get the Id. But I need both!

enter image description here

enter image description here

I should probably also point out that I'm building the solution on a very stripped down version of SharePoint, so all I have to play with is .xsl and .webpart files, and whichever settings I can make in the online editor (no access to SharePoint Designer).

Last but not least, my SharePoint knowledge level is noob. :)

share|improve this question

2 Answers 2

up vote 1 down vote accepted

I found a solution that works for me. I doesn't solve the original problem (getting both Name and ID) - it proposes another solution.

Instead of trying to get both Name and ID (I thought I needed the ID to build the URL to the member's page), I used the following to look up the URL of the member:

<xsl:variable name="SafeLinkUrl">
    <xsl:call-template name="OuterTemplate.GetSafeLink">
        <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
    </xsl:call-template>
</xsl:variable>

So instead of this:

<a href="http://<my_site>/sites/<my_sub_site>/_layouts/userdisp.aspx?ID={@ID}">
    <xsl:value-of select="@Member" />
</a>

I ended up with this

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

in the itemstyle.xsl. Much cleaner - and it works! :)

share|improve this answer

Technically the People Picker column values are a span with a BUNCH of attributes stuck to it. Here is normally how I get the two main basics from it:

ID => <xsl:value-of select="substring-before(substring-after(@PickerColumn, 'ID='), '&amp;')" />

Display Name => <xsl:value-of select="substring-before(substring-after(@PickerColumn, '&gt;'), '&lt;')" />

Haven't used the last one in a while so let me know if it doesn't work. Hope that helps!

share|improve this answer
    
Well, that's what I thought too, but it seems that when passing the column to a Content Query web part, you can only get one (1) of the attributes. When I do the same thing for a Link type column, I'm able to get comma separated attributes: URL = http://google.com, Google Search –  spacedoom Jun 26 at 6:00
    
I've added an image to the question, showing the "Show field" selection that affects which attribute is sent to the content query. I'd like an "All attributes as comma separated values" option! :) –  spacedoom Jun 26 at 6:10

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.