This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Identifing links in text
- From: "Andrew Welch" <awelch at piper-group dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 6 Jun 2002 09:21:58 +0100
- Subject: RE: [xsl] Identifing links in text
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Joerg,
Joerg wrote:
>Hi Andrew,
>
>of course, my template can be shortened a bit. But your template
doesn't
>do what was required - or where is your recursiion ;-)
Ok, so it would only work for one url per text() node, but I still think
its pretty neat
cheers
andrew
Joerg
Andrew Welch wrote:
>>I need some way to identify a link like statement in a tagged piece
>>of text.
>
>
> I know Joerg has already given you a solution, but I thought I would
> offer a slightly smaller and simpler template that will do trick:
>
> <xsl:template match="text()">
> <xsl:choose>
> <xsl:when test="contains(.,'http://')">
> <xsl:variable name="theURL"
>
select="concat('http://',substring-before(substring-after(.,'http://'),'
> '))"/>
> <xsl:value-of select="substring-before(.,$theURL)"/>
> <a href="{$theURL}"><xsl:value-of select="$theURL"/></a>
> <xsl:value-of select="substring-after(.,$theURL)"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select="."/>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
> This checks to see if the text() content of the node contains
'http://'.
> If it doesnt it just outputs the text as usual, but if it does then it
> separates the string into three bits (before url, url, after url) and
> outputs them with the url marked up into a link.
>
> text manipulation is always hard with xslt but it can be good to mess
> around with the string handling functions to get what you need
>
> cheers
> andrew
>
>
>
>
> -----Original Message-----
> From: Charles Knell [mailto:cknell@onebox.com]
> Sent: 04 June 2002 18:37
> To: xsl-list@lists.mulberrytech.com
> Subject: Re: [xsl] Identifing links in text
>
>
> ---- Raimund Kammering <Raimund.Kammering@desy.de> 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
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.350 / Virus Database: 196 - Release Date: 17/04/2002
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.350 / Virus Database: 196 - Release Date: 17/04/2002
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list