Subject: Re: [xsl] Re: Search and Replace to add HTML tags From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Wed, 01 Jul 2009 10:04:53 -0400 |
One more thing I am trying to do within the same node is to search for any text that starts w/ "http://" and take that and the text that follows it and turn it into an active hyperlink.
This is the code I was using to perform this action and now understand that I need to combine this along w/ the action for searching for specific words and wrapping tags around them within the same template definition (ReleaseNote). Unfortunately, I have not been successful and do not understand how to perform 2 different search and replace functions within the same node.
Here is the original code which obviously does not work as the ReleaseNote template definition overwrites the changes made from the text template definition. But I do not understand how to combine both actions within the ReleaseNote template definition.
t:\>type sharon.xml <test> <Row> <ReleaseNote>Before: The application did this. Now: The application does this. Here is a link: http://myurl.com Note: The application may also do this.</ReleaseNote> </Row> <Row> <ReleaseNote>Before: The application did not do this. Now: The application does this.</ReleaseNote> </Row> </test>
<xsl:template match="ReleaseNote"> <td> <xsl:analyze-string select="." regex="Before:|Enhancement:|Informational:|Note:|Now:"> <xsl:matching-substring> <b><xsl:value-of select="."/></b> </xsl:matching-substring> <xsl:non-matching-substring> <xsl:call-template name="hyperlink"/> </xsl:non-matching-substring> </xsl:analyze-string> </td> </xsl:template>
<xsl:template name="hyperlink"> <xsl:param name="string" select="string(.)"/> <xsl:analyze-string select="$string" regex="http://[^ ]+"> <xsl:matching-substring> <a href="{.}" target="new"> <xsl:value-of select="."/> </a> </xsl:matching-substring> <xsl:non-matching-substring> <xsl:value-of select="."/> </xsl:non-matching-substring> </xsl:analyze-string> </xsl:template>
<xsl:template match="@*|node()"><!--identity for all other nodes--> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
-- Possible July/August XSLT/XQuery/XSL-FO training in Oakland/CA/USA Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Re: Search and Replace to add, Sharon_Harris | Thread | [xsl] Re: Search and Replace to add, Sharon_Harris |
[xsl] Re: Search and Replace to add, Sharon_Harris | Date | [xsl] how to xpath the *value* of a, dan haig |
Month |