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

Re: Identifing links in text

Subject: Re: Identifing links in text
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Tue, 04 Jun 2002 21:41:30 +0200
xsl text and link
Hello Raimund,

it's not necessary to use an extension function, it's possible to do it with a recursive template. The other question is, if it is always the best solution.

<xsl:template match="text">
<xsl:call-template name="add-link">
<xsl:with-param name="string" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="add-link">
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="contains($string, 'http://')">
<xsl:value-of select="substring-before($string, 'http://')"/>
<a href="http://{substring-before(substring-after($string, 'http://'), ' ')}">
<xsl:text>http://</xsl:text>
<xsl:value-of select="substring-before(substring-after($string, 'http://'), ' ')"/>
</a>
<xsl:text> </xsl:text>
<xsl:call-template name="add-link">
<xsl:with-param name="string" select="substring-after(substring-after($string, 'http://'), ' ')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


I used a single space as end of the link.

Regards,

Joerg

Charles Knell wrote:
---- Raimund Kammering <Raimund.Kammering@xxxxxxx> wrote:

Hallo Everybody,

I need some way to identify a link like statement in a tagged piece
of
text. To make it more clear
here is a small sample the XML code migth look like:

<entry>
<keyword>Info</keyword>
<text>Some amount of plain text. But inside may appear a
statement like this: http://www.some-server.com and this shall
be shown as a usual (blue) link in a browser.</text>
<entry>


You've identified one of XSLT's weaknesses. You will most likely have
to write an extension function incorporating regular expression processing
so you will be able to find and wrap the links with the <a href=""></a>
tags.

I believe that most processors provide a means of extending xsl's built-in
functions. I know that you can write JavaScript extensions for MSXML
(because I've done it) and that Oracle's processor supports extension
functions written in Java (because I've researched, but not written any).

It is only with the most recent version of Java (J2SE 1.4 ?) that a standard
API for regular expression processing has been included. JavaScript has
very good regular expression capabilities, so if you are using MSXML,
you will probably not have too much trouble in writing the function.

If you're willing to "think outside the box" for this, you could easily
write a Perl script to pre-process this file before it gets sent to the
XSL processor.


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-2007 All Rights Reserved.