Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT Select Text; Add href

Reply
Thread Tools

XSLT Select Text; Add href

 
 
joealonso@gmail.com
Guest
Posts: n/a
 
      05-19-2005
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
(NYSEG)

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">
<xslaram 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>
<xsltherwise>
<xsl:value-of select="$str"/>
</xsltherwise>
</xsl:choose>
</xsl:template>

Thanks in advance!

 
Reply With Quote
 
 
 
 
joealonso@gmail.com
Guest
Posts: n/a
 
      05-19-2005
Nevermind I figured it out. Below is the code...

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

<xsl:template name="hyperlink">
<xslaram 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>
<xsltherwise>
<xsl:value-of select="$string" />
</xsltherwise>
</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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BASE HREF and A HREF="#" onclick="..." Vincent van Beveren Javascript 2 07-06-2006 08:33 AM
href="javascript:func()" vs href="#" onclick="javascript:func()" CRON HTML 24 06-20-2006 08:05 PM
onClick method question (this.href and document.location.href) yogesh.bhardwaj@gmail.com Javascript 2 02-03-2005 02:38 PM
difference between location.href and window.location.href? saiho.yuen Javascript 3 09-14-2004 06:51 PM
Problem: Setting MSIE iframe innerHTML change relative href/src to absolute href/src Soren Vejrum Javascript 4 07-05-2003 01:47 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57