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?
You could use:
<xsl:value-of select="substring-before(@[ColumnName],',')"/>
or whatever the separator is.
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.
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>
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>
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.
The easiest way to do this is with SharePoint designer:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.