[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: auto-hyperlinker (how to search/replace)?

Subject: Re: auto-hyperlinker (how to search/replace)?
From: Terence Kearns <terencek@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 03 Jun 2003 11:27:36 +1000
hyperlinker
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.