Unlocking the Mysteries of Data View Web Part XSL Tags – Part 12 – Miscellaneous: Person or Group Columns
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 1: Overview
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 2 – <xsl:template>
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 3 – <xsl:call-template>
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 4 – <xsl:with-param>
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 5 – <xsl:param>
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 6 – <xsl:variable>
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 7 – <xsl:for-each>
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 8 – <xsl:sort>
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 9 – <xsl:if>
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 10 – <xsl:choose>
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 11 – <xsl:value-of>
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 12 – Miscellaneous: Person or Group Columns
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 13 – Miscellaneous: String Functions
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 14 – Miscellaneous: ddwrt Namespace Functions
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 15 – Miscellaneous: Field / Node Functions
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 16 – <xsl:attribute>
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 17 – <xsl:comment> and <xsl:text>
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 18 – Miscellaneous – Some Math / Number Functions
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 19 – Miscellaneous – More Math / Number Functions
- Unlocking the Mysteries of Data View Web Part XSL Tags – Part 20 – <xsl:import>
- Unlocking the Mysteries of the SharePoint Data View Web Part XSL Tags eBook Now Available
Cross-posted from EndUserSharePoint.com…
As I got into writing this “last” article in the series, I realized that between the things people have asked me over the course of the series and the things I think might be useful, I have far more than one more article to write. I think I’ll keep this series going for a while (Mark willing) and try to cover more of the things that you can do in Data View Web Parts (DVWPs), XSL-based or not.
Person or Group columns are pretty unique in that they contain a big blob of markup which represents a sort of “person object”. They look like a big mess, but they actually contain a great deal of information. Here’s what a typical Person or Group column might contain.
<xsl:value-of select="@Author"/>
renders something like
<nobr><span><A HREF="/_layouts/userdisp.aspx?ID=15">Rufus T. Farnsworth</A><img border="0" height="1" width="3" src="/_layouts/images/blank.gif"/><a href='javascript:' onclick='IMNImageOnClick();return false;' class='ms-imnlink'><img name='imnmark' title='' border='0' height='12' width='12' src='/_layouts/images/blank.gif' alt='No presence information' sip='[email protected]' id='imn_1,type=smtp'/></a></span></nobr>
There will be some variation based on whether you’ve got presence turned on, what type of authentication you are using, etc., but as you can see, it’s messy. Since the column value contains markup, when you display it using the <xsl:value> tag, you should also use the disable-output-escaping=”yes” attribute.
<xsl:value-of select="@Author" disable-output-escaping=”yes”/>
renders as
Rufus T. Farnsworth
which is a link to the user profile page (_layouts/userdisp.aspx
) for this user.
Even worse, if the same user is displayed multiple times in the DVWP, the markup won’t usually even match! Here’s the same user displayed from a different item in the same list:
<nobr><span><A HREF="/_layouts/userdisp.aspx?ID=15">Rufus T. Farnsworth</A><img border="0" height="1" width="3" src="/_layouts/images/blank.gif"/><a href='javascript:' onclick='IMNImageOnClick();return false;' class='ms-imnlink'><img name='imnmark' title='' border='0' height='12' width='12' src='/_layouts/images/blank.gif' alt='No presence information' sip='[email protected]' id='imn_4,type=smtp'/></a></span></nobr>
As you can see, id='imn_1,type=smtp'
and id='imn_4,type=smtp'
don’t match. So if you try to do sorting or grouping by a Person or Group column, you get “unexpected” results. (Most of us just call this the “wrong answer”).
One way to deal with the variations in the Person or Group column values is to substring out the user’s unique ID and use that for your sorting or grouping column:
<xsl:variable name=”UserID” select="substring-before(substring-after(@Author, ‘ID=’), ‘"’)"/>
The variable $UserID
will now contain 15 for both versions of this same user.
If you don’t want to display the user’s name as a hyperlink, you can do the same sort of substring trick. Simply substring out the actual name:
<xsl:variable name="UserAccount" select="substring-after(substring-before(substring-after(@Author, ‘ID=’), ‘<’), ‘>’)"/>
In this example, the variable $UserAccount = "Rufus T. Farnsworth"
.
I’ve been asked many, many questions about Person or Group columns over the years, but these two tips address the majority of the questions.
I’ve used some of the XSL string functions above, and those functions can be really useful in many other ways as well. In my next article, I’ll go over what string functions are available and how you might use them in your DVWP’s XSL.
I want to display the summary or roll-up report using DVWP Something like
Country- Manufacturing Unit – Department – Total Income (Summary)
USA- Desktop Mfg-Keyboards-10000
USA-Desktop Mgg-Monitors – 20000
this is kind of aggregatet report. please advise, how to achieve this. Now I get the report grouped by fields and the group footer shows total.
Saran:
It’s a matter of editing the XSL to emit the markup you’d like. I find that the way that SharePoint Designer does grouping is really hard to follow, so I generally just write my own XSL.
M.
June 2012: The “strange” Mystery of @Author empty appears in Italy. Nothing to do. It’s one of many bugs of Sharepoint that the time didn’t resolved.
Sharepoint 2010, Issue List, EditForm.aspx, Designer 2010: @Author = NULL !!! So: Impossible to use Sharepoint to implement a simple logic to showing edit field only to issue creator (feature that could be native in a good KM platform).
ferdinando:
I can’t recall ever seeing an empty Author column. Can you explain the context a bit?
M.
Mark,
I am using DV to display list items. I want to display author name and title from a Person & Group field called Author. I am able to display the name which is linked to the profile but how do I obtain the title from this field to display ?
which displays
Snow, John
but I also want to display the title along with the formatted name like
John Snow
Web Developer
Please help. Thanks.
Thanks Mark for providing such good instructions on String Functions I was able to figure it out. I am applying the String Function twice to PubAuthor field – first one to get the linked Name and the next to get the Job Title.
I wanted to post the string but its not allowing me to post HTML here.
Thanks again.
Hello marc,
I am using the DataformWebpart on SharePoint 2010 to display data from multiple document Libraries.
I have allowed the “Sort & Filter on Headers” thus now I have a problem in filtering from the header of (Modified By) as the filter dropdown results are displayed as html (span class=…).
I really hope you can help on this as I have used the method discribed above but it didnt helped in the filtered dropdown results.
The weird thing is that this error does not occur in the xsltlistviewwebpart.
Thank you,
DH
DH:
I think we have to call that a “bug”. You can definitely fix it by diving into the XSL and updating it manually to handle the date correctly, but I don’t have a fix handy for you, unfortunately.
M.
Thanks :)