[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: auto-hyperlinker (how to search/replace)?
OK, that code works great after 1 minor modification :)
Here is the code <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="hyperLinkIndicator" select="'http://'" /> <xsl:template name="hyperlinker"> <xsl:param name="string" select="string()" /> <xsl:choose> <xsl:when test="contains($string, $hyperLinkIndicator)"> <xsl:value-of select="substring-before($string, $hyperLinkIndicator)" /> <xsl:variable name="rest" select="substring-after($string, $hyperLinkIndicator)" /> <xsl:variable name="url" select="concat($hyperLinkIndicator, substring-before($rest, ' '))" /> <a href="{$url}"> <xsl:value-of select="$url" /> </a> <xsl:call-template name="hyperlinker"> <xsl:with-param name="string" select="substring-after(concat($hyperLinkIndicator,$rest), $url)" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$string" /> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> I moved the search text into a script param called hyperLinkIndicator the only change I had to make to the original script was the select statement in the recursive call-template directive. It now reads substring-after(concat($hyperLinkIndicator,$rest), $url) instead of substring-after($rest, $url) A very useful script indeed which can be modified for other tokens. It's worth mentioning that you shouldn't fall into the trap that I did. I assigned the output of that script to a variable like so <xsl:variable name="foo"> <xsl:call-template name="hyperlinker"> <xsl:with-param name="string" select="text()" /> </xsl:call-template> </xsl:variable> and then proceeded to access $foo like so <xsl:value-of select="$foo" /> needless to say, my hyperlinks never showed up until I used <xsl:copy-of select="$foo" /> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|