Reputation:
I have some document URLs stored in a Sharepoint publishing column. When I output the info into a HTML page using:
<xsl:value-of select="@[ColumnName]" />
in ItemStyle.xml
, I get [url]
, [document name]
in the page. I would like to display this as a URL can anyone help with the XSL?
Upvotes: 2
Views: 21854
Reputation: 12806
In SharePoint 2013 you have to do things a bit differently because the @Url
attribute is is no longer delimited with a comma. There is now a .desc
sub property of @Url
. Below is an example of how this works hopefully this saves someone else some time.
<xsl:template name="dvt_1.rowview">
<xsl:if test="string-length(@URL) > 0">
<div class="link-item item">
<a title="{@Comments}" target="_blank" href="{@URL}">
<xsl:value-of select="@URL.desc" />
</a>
</div>
</xsl:if>
</xsl:template>
Upvotes: 0
Reputation:
This hopefully helps. It shows "Project Site" when the hyperlink is entered and spaces when not.
<!--Project Site--><TD Class="{$IDAAO2UG}">
<xsl:variable name="Field" select="@Project_x0020_Site" />
<xsl:choose>
<xsl:when test="substring-before(@Project_x0020_Site, ', ')=''"><xsl:value-of select="substring-after(@Project_x0020_Site, ', ')" /></xsl:when>
<xsl:otherwise><A HREF="{substring-before(@Project_x0020_Site, ', ')}">
<xsl:choose>
<xsl:when test="substring-after(@Project_x0020_Site, ', ')=''"><xsl:value-of disable-output-escaping="no" select="substring-before(@Project_x0020_Site, ', ')" /></xsl:when>
<xsl:otherwise><xsl:value-of select="substring-after(@Project_x0020_Site, ', ')" /></xsl:otherwise>
</xsl:choose>
</A></xsl:otherwise>
</xsl:choose>
</TD>
Upvotes: 0
Reputation: 6485
Thanks everyone, in the end I figured out the following based on a post at sguk
<xsl:variable name="Doc">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="@DocumentLink1"/>
</xsl:call-template>
</xsl:variable>
with the following a tag code:
<a href="{substring-before($Doc,',')}">
<xsl:value-of select="substring-after($Doc,',')" />
</a>
or for an image:
<xsl:variable name="Image">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="@img" />
</xsl:call-template>
</xsl:variable>
with the following img tag:
<img src="{substring-before($Image,',')}" alt="{substring-after($Image,',')}" />
I'm posting the solution back here as this proved ludicrously hard to figure out (probably my fault as I don't really 'get' XSL) but just in case anybody is looking for it, this code outputs images or links from the 'Hyperlink or Picture' column type in Sharepoint.
Upvotes: 3
Reputation: 2172
The easiest way to do this is with SharePoint designer:
Upvotes: 0
Reputation: 2292
Another thing you can do is to take a list that shows URLs properly (like a Links list) and use SharePoint Designer to convert it to a DataView WebPart. In there will be the proper XSL for doing the conversion.
Upvotes: 0
Reputation: 706
You could use:
<xsl:value-of select="substring-before(@[ColumnName],',')"/>
or whatever the separator is.
Upvotes: 4