Subject: Re: [xsl] Identifing links in text From: Joerg Heinicke <joerg.heinicke@xxxxxx> Date: Wed, 05 Jun 2002 21:19:30 +0200 |
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@xxxxxxxxxx] Sent: 04 June 2002 18:37 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] Identifing links in text
---- 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.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Identifing links in text, Andrew Welch | Thread | RE: [xsl] Identifing links in text, Andrew Welch |
[xsl] RE: [slightly OT] question ab, Amanda Birmingham | Date | [xsl] Re: RE: accessing node[$posit, spiders frommars |
Month |