[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
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:
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Re: [xsl] Identifing links in text
Subject: Re: [xsl] Identifing links in text From: Joerg Heinicke <joerg.heinicke@xxxxxx> Date: Tue, 04 Jun 2002 21:41:30 +0200 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Identifing links in text, Charles Knell | Thread | RE: [xsl] Identifing links in text, Andrew Welch |
Re: [xsl] Escaping newlines in an X, Thomas B. Passin | Date | Re: [xsl] Elements of non-actual po, Joerg Heinicke |
Month |