Here's an approach you could use. The "choose's" and "substring-before's"
and "substring-after's" get kind of shaggy. And choice of substring
conditions make some pretty lazy assumptions about the expected form of the
url's, but you get the idea:
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()" priority="2">
<xsl:choose>
<xsl:when test="contains(.,'http')">
<xsl:variable name="after.com" select="substring-after(.,'.com')" />
<xsl:value-of select="substring-before(.,'http')" />
<a>
<xsl:attribute name="href">
<xsl:value-of
select="concat('http',substring-after(substring-before(.,'.com'),'http'),'.c
om')" />
</xsl:attribute>
<xsl:value-of
select="concat('http',substring-after(substring-before(.,'.com'),'http'),'.c
om')" />
</a>
<xsl:call-template name="lazy-recurs">
<xsl:with-param name="after-.com">
<xsl:value-of select="$after.com" />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="lazy-recurs">
<xsl:param name="after-.com" />
<xsl:choose>
<xsl:when test="contains($after-.com,'http')">
<xsl:variable name="after.com"
select="substring-after($after-.com,'.com')" />
<xsl:value-of select="substring-before($after-.com,'http')" />
<a>
<xsl:attribute name="href">
<xsl:value-of
select="concat('http',substring-after(substring-before($after-.com,'.com'),'
http'),'.com')" />
</xsl:attribute>
<xsl:value-of
select="concat('http',substring-after(substring-before($after-.com,'.com'),'
http'),'.com')" />
</a>
<xsl:call-template name="lazy-recurs">
<xsl:with-param name="after-.com">
<xsl:value-of select="$after.com" />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$after-.com" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
-----Original Message-----
From: Ghulam Abbas [mailto:abbasg_99(_at_)yahoo(_dot_)com]
Sent: Friday, April 16, 2004 12:53 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Converting embedded URLs int hot links via XSL
Here is the sample xml
<strings>
<str>Test url string: 'http://www.yahoo.com' and one
more url "https://www.yahoo.com"</str>
</strings>
So, is there a way to extract the urls above from str
and then convert them into hotlinks. The desired html
is something like
Test url string: <a href="http://www.yahoo.com"
target="_blank">'http://www.yahoo.com'</a> and one
more url <a href="https://www.yahoo.com"
target="_blank">"https://www.yahoo.com"</a>
I've tried recursion but it doesn't work. Any ideas???
Thanks,
Abbas
__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html
--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--