XSLT Select Text; Add href

J

joealonso

Problem:

I have an xml news feed:

blah blah yesterday by the news from General Motors (NYSE:GM) that
helped bring the market to a three-week high blah blah We all know that
the old days are gone, when IBM (NYSE:IBM) employees wore dark suits
and ties, and white shirts, worked nine to five blah Procter & Gamble
(NYSE:pG)

I need to select the text between "NYSE:" and ")" and add <a
href="page.asp?symbol=IBM">$string</a>

does anyone know how to do this? I've got an extra Half-Life2 serial
number for the first person to figure it out.

I've tried something like...

<xsl:template name="links">
<xsl:param name="str"/>
<xsl:choose>
<xsl:when test="contains($str,'NYSE')">
<a href="#id{substring-after($str,'NYSE')}"><xsl:value-of
select="substring-after($str,'NYSE')"/></a>
<xsl:call-template name="links">
<xsl:with-param name="str" select="substring-after($str,'NYSE')
and substring-before($str,')')"/>
</xsl:call-template>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="$str"/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

Thanks in advance!
 
J

joealonso

Nevermind I figured it out. Below is the code...

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="html" version="4.01" encoding="iso-8859-1"
indent="yes" />

<xsl:template name="hyperlink">
<xsl:param name="string" select="string()" />
<xsl:choose>
<xsl:when test="contains($string, '(NYSE:') and contains($string,
')')">
<xsl:variable name="url"
select="substring-after(substring-before($string, ')'), '(NYSE:')" />
<xsl:variable name="rest" select="substring-after($string,
')')"/>
<xsl:variable name="before" select="substring-before($string,
$url)"/>
<xsl:value-of select="$before"/>
<a href="/test.asp?symbol={$url}"><xsl:value-of
select="$url"/></a>)
<xsl:call-template name="hyperlink">
<xsl:with-param name="string" select="$rest" />
</xsl:call-template>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="$string" />
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>


<xsl:template match="/response/content_servlet_results/result">
<h5><xsl:value-of select="Headline" /></h5>
<xsl:for-each select="Story/P">
<p>
<xsl:call-template name="hyperlink">
<xsl:with-param name="string" select="."/>
</xsl:call-template></p>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

- Joe Alonso
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top