Put MySite link of creator in CQWP using itemstyle.xsl

This will show you how to correctly link the creator of an item to their mysite in a Content Query WebPart.

Step 1:
Declare the variable “authormysite” and the author string of “UserLookup”. We pull the “Login” parameter, because the username is what is appended on the mysite link out of the box.

<xsl:variable name="authormysite">
<xsl:value-of select="ddwrt:UserLookup(string(@Author) ,'Login')" />
</xsl:variable>

Step 2:
Create the link to the mysite page, appending the new variable’s value that you just created.

< a href="https://m.isb.bj.edu.cn/Person.aspx?accountname={$authormysite}" ></ a>

Step 3:
Within the link, you want to declare the value of @Author to get their full display name.

<xsl:value-of select="@Author" />

Final code:

<xsl:template name="mysitelink" match="Row[@Style='mysitelink']" mode="itemstyle">
<xsl:variable name="authormysite">
<xsl:value-of select="ddwrt:UserLookup(string(@Author) ,'Login')" />
</xsl:variable>

< a href="https://m.isb.bj.edu.cn/Person.aspx?accountname={$authormysite}">
<xsl:value-of select="@Author" />
</ a>

</xsl:template>

About bentedder

Ben Tedder is a front-end web developer. He loves WordPress, SharePoint, and Drupal, along with jQuery, CSS, and good 'ol HTML. +Ben Tedder on Google or follow @bentedder

Comments

I try to respond personally, but things get busy sometimes :)
  1. Florian says:

    Hi Ben,
    i tried your solution for our search center so users can click on authors name in the results to be redirected to the authors’ mysite but didn’t get it to run.
    I get the error that the webpart can’t be shown.

    Here’s a snippet of my edited XSL:

    <!–

    –>

    I hope you can help me.

    • Florian says:

      I see HTML-Tags are disabled so i removed the first brackets( in hope it will work now):
      div class=”srch-Metadata2″>
      xsl:template name=”mysitelink” match=”Row[@Style='mysitelink']” mode=”itemstyle”>
      xsl:variable name=”authormysite”>
      xsl:value-of select=”ddwrt:UserLookup(string(@Author) ,’Login’)” />
      /xsl:variable>
      a href=”https://m.isb.bj.edu.cn/Person.aspx?accountname={$authormysite}”>
      xsl:value-of select=”@Author” />
      /a>

      /xsl:template>

      xsl:with-param name=”author” select=”author” />
      /xsl:call-template>–>
      xsl:call-template name=”DisplayDate”>
      xsl:with-param name=”write” select=”write” />
      /xsl:call-template>

Join the discussion!