开发者

Replace or append to link

I am working on an old Sitecore 4 solution where i need to manipulate the output of a field slightly. I have a normal field (Message)开发者_开发技巧 that i am outputting via <sc:html field="message"/> or <xsl:value-of select="sc:fld('Message',.)"/>.

Either works just fine.

I now have to search in the "Message" field for links, and then i need to append the date to the end of the link like so "<a href="http://www.thisismydomain.com?utm_campaign=01-01-2011">this is my link</a>

How could i accomplish the above in XSLT 1.0?


My understanding is that you want to do a find and convert urls to links.

I see these as your Options: 1. Xpath 2.0 supports functions like matches and replace which use regular expressions. See http://www.w3schools.com/xpath/xpath_functions.asp#string or http://www.w3.org/TR/xpath-functions/#func-replace. I'm not sure if sitecore supports Xpath 2.0. From memory i dont think it supports Xpath 2.0. If it does you are in luck and you can do something similar like this

<xsl:choose>
            <xsl:when test="contains(., 'http.*')">
              <strong><xsl:value-of select="replace(.,'http.*','REPLACED TEXT')"/></strong>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="."/>
            </xsl:otherwise>
          </xsl:choose>
  1. Find and replace the Message values before or after it gets to XSL transformation just before you render the output.

Things to what out for:

  1. Why do you have URLs without showing up as Links in Message tag? Is it a case where you are not using WYSIWYG for content?
  2. If this seems to be too much work, which sounds like it is. You can have a workaround to have a javascript at the end of the page. Which will simply find and replace URLs to links. Make sure you don't double up. Regex is your friend here.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜