Wednesday, March 01, 2006

Formatting links properly in a frontpage dataview

When creating a dataview for a list using the getlistitems function of the “lists” web service you can display a list from a remote site in your site, without having to develop a custom web part. However, inserting a link list from a web service shows the links in full text - for example : ", msd2d" This is because sharepoint stores the link's title and link in a single field with a comma and a space seperating the title and the link. What you need to do to solve this, is change the xsl of the dataview so that the link will only show the title, while the link will include only the link. In frontpage, click the dataview and switch to code view. The selected area is the entire dataview defenition. You will need to scroll down and locate the tag definition inside (location may change depending on your list and view). Change the tag using xsl “substring-before” and “substring-after” functions: Add an xsl variable that will hold the full link text : Change the xml of the href attribute to insert the text before the comma: Change the xml of the text to insert the text after the comma and the text: This can be confusing, so use my sample code below - just copy and paste it over the existing tag. You should note that the link field may be named differrently in your list. in a default links list it is named “ows_URL” but in your list you may need to check what the name is. just look in the dataview code before pasting over it. Code Sample:
<a> <xsl:variable name="linktext" select="@ows_URL"/> <xsl:attribute name="href"> <xsl:value-of select="substring-before($linktext,', ')"/> </xsl:attribute> <xsl:value-of select="substring-after($linktext,', ')"/> </a>

1 comment:

Anonymous said...

Nice post and example! We need more xslt / data view examples in the community...