Wednesday, September 25, 2013

SharePoint XSLT and Hyperlink

Content Query webpart is like a swiss army knife for developers who have the task to display various SharePoint content like lists, libraries and media on any page. And XSLT is the design language you will have to use to customize the UI and layout of the content displayed within the Content Query web part.

This post details about how to pull a Hyperlink column from a link and display on the page.

Create a new variable

<xsl:variable name="DownloadLink">
          <xsl:call-template name="OuterTemplate.GetTitle">
            <xsl:with-param name="Title" select="@Url"/>
          </xsl:call-template>
</xsl:variable>

Note: @Url is the the actual name of the  Hyperlink column in the list.


Display the link


<div class="dLink">
    <a href="{substring-before($DownloadLink,',')}">
    <xsl:value-of select="substring-after($DownloadLink,', ')" />
    </a>
</div>

That's it!

Save your changes and look for the Hyperlink column on the page in your Content Query web part.