Outputting SharePoint Hyperlink Column as URL

2019-07-09 01:42发布

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?

6条回答
来,给爷笑一个
2楼-- · 2019-07-09 02:19

The easiest way to do this is with SharePoint designer:

  • click the field that shows "http://link, description"
  • a box with an > will appear, click it and you will get a "common xsl:value-of tasks" flyout.
  • It will have the field name and type, with the type set to "text".
  • Change the type to "hyperlink" and you will get a box allowing you to format the hyperlink. It will have all the necessary xsl already populated but you can input your own text or remove the link.
查看更多
Fickle 薄情
3楼-- · 2019-07-09 02:20

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>
查看更多
成全新的幸福
4楼-- · 2019-07-09 02:25

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) &gt; 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>
查看更多
地球回转人心会变
5楼-- · 2019-07-09 02:36

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.

查看更多
该账号已被封号
6楼-- · 2019-07-09 02:41

You could use:

<xsl:value-of select="substring-before(@[ColumnName],',')"/>

or whatever the separator is.

查看更多
爱情/是我丢掉的垃圾
7楼-- · 2019-07-09 02:41

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.

查看更多
登录 后发表回答