[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Display link text as a hyperlink
2008/8/6 Brent Solly <ultra@xxxxxxxxx>: > I have an xml file that contains this character sequence: 'www.gamefaqs.com' . > > Primary Problem: > After I convert the 'www' text to hyperlink format, the xsl displays it as plain text, but I would like to display it has a hyperlink. > > Secondary: > I am aware that the url may also contain subfolders like: www.gamefaqs.com/console/n64 OR different a suffix like www.gamefaqs.ca., but right now I'll focus on .com, but feel free to make suggestions :) . > > > <?xml version="1.0" encoding="UTF-8"?> > <rss> > <channel> > <item> > <description>More information on this game can be found at (www.gamefaqs.com)</description> > </item> > </channel> > </rss> > > <?xml version="1.0" encoding="UTF-8"?> > > <xsl:stylesheet > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="2.0"> > <xsl:strip-space elements="*" /> > <xsl:output method="html" encoding="UTF-8"/> > > > <xsl:template name="globalReplace"> > <xsl:param name="outputString"/> > <xsl:param name="target"/> > <xsl:param name="replacement"/> > <xsl:choose> > <!--Begin Test --> > <xsl:when test="contains($outputString,$target)"> > > <xsl:value-of select= > "concat(substring-before($outputString,$target), > $replacement)"/> > <xsl:call-template name="globalReplace"> > <xsl:with-param name="outputString" > select="substring-after($outputString,$target)"/> > <xsl:with-param name="target" select="$target"/> > <xsl:with-param name="replacement" > select="$replacement"/> > </xsl:call-template> > </xsl:when> > <!--End Test--> > > <xsl:otherwise> > <xsl:value-of select="$outputString"/> > </xsl:otherwise> > > </xsl:choose> > </xsl:template> > <xsl:template match="rss"> > <xsl:call-template name="globalReplace"> > <xsl:with-param name="outputString" select="."/> > <xsl:with-param name="target" select="'www'"/> > <xsl:with-param name="replacement" select="concat('<a href="http://www',substring-before(substring-after(.,'www'),substring-after(.,'com')),'">',substring-before(substring-after(.,'www.'),'.com'),'</a>')"/> > > </xsl:call-template> > </xsl:template> > > > </xsl:stylesheet> whoooaaaaah there.... you've set off down the wrong road (like so many others) and it will only end in tears and resentment. It's completely the wrong apporach. To do a search and replace on a string use either replace() or xsl:analyze-string: <xsl:analyze-string select="." regex="$the-regex"> <xsl:matching-substring> <a href="http://{.}">http://<xsl:value-of select="."/></a> </xsl:matching-substring> <xsl:non-matching-substring> <xsl:value-of select="."/> </ </ -- Andrew Welch http://andrewjwelch.com Kernow: http://kernowforsaxon.sf.net/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|