views:

2032

answers:

7

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?

+2  A: 

You could use:

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

or whatever the separator is.

Waldek Mastykarz - MOSS MVP
A: 

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.

Mark Mascolino
+1  A: 

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.

toomanyairmiles
A: 

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.
ArjanP
A: 

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>
A: 

Thank you very much for the post. I was stuck with the similar issue at my client. The URL field was being displayed twice with a "," in between. The substring function helped me remove the duplicate and now its working just the way I wanted it.

Thank you again.