mardi 27 janvier 2015

Converting text field to hyperlink via xslt



In my list I have a field for just a regular old text field - all default. It's just a plain, default text field named [TextLink].


And in my fldtypes_custom.xsl file I have included some lines to convert that line of text into a hyperlink. In my CSS (in the MasterPage) I style up a little link icon.


The effect is (This works like a charm for callto links) in the list only the icon shows, and when you click on it, you follow the hyperlink, like this:


hyperlink icon button via xsl


My XSL



<!-- Turn the ForumLink field into a link icon-->
<xsl:template match="FieldRef[@Name='TextLink']" mode="Text_body">
<xsl:param name="thisNode" select="."/>
<xsl:variable name="currentValue" select="$thisNode/@*[name()=current()/@Name]" />
<xsl:choose>
<xsl:when test="$currentValue=''">
<span></span>
</xsl:when>
<xsl:otherwise>
<span><a href="{$currentValue}" class="textlink" target=""></a></span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


My CSS



.textlink {
background-repeat: no-repeat;
background-position: center;
height: 16px;
width: 100%;
padding: 1px 16px;
}
.textlink {background-image: url("/_layouts/myimages/link.png"); }


Now, my problem is that SharePoint is trying to hyperlink the text too, and it warps the hyperlink value to something like this. Notice how it starts with my portal's own url, and how the a element's tags are included in the hyperlink value:



http://ift.tt/1ztxifw href="http://ift.tt/1D63eU9">http://ift.tt/1ztxfQV;


But this is the real value of the link-icon-button that I see in Firebug:



<a target="" class="textlink" href="<a href="http://ift.tt/1D63eU9">http://ift.tt/1ztxfQV;"></a>


Is there a way to fix this? My xsl should be what creates the hyperlink; but it seems to be fighting with SharePoint over who gets to do it. Is there another way to write the xsl?








0 commentaires:

Enregistrer un commentaire