Subject: Re: [xsl] Search and Replace to add HTML tags From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 30 Jun 2009 13:38:08 -0400 |
I am trying to wrap specific text in a string within HTML tags. For example, if a strings contains the word "Note:", then I want to enclose this word within a set of bold tags (<b>Note:</b>). I do not have control over the XML data source and cannot modify the structure/schema.
I have tried using the replace function to search for the specific text and then replace it with a defined variable.
The variable contains the text wrapped within the HTML tags. Unfortunately, only the content within the variable is getting pulled and the HTML tags are being ignored.
Can anyone tell me how to get the tags added as well during the search and replace?
XML excerpt: <Row> <ReleaseNote>Before: The application did this. Now: The application does this. 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>
XSLT excerpt: <xsl:variable name="NoteBold"><b>Note:</b></xsl:variable> <xsl:variable name="BeforeBold"><b>Before:</b></xsl:variable> <xsl:variable name="NowBold"><b>Now:</b></xsl:variable>
<xsl:template match="text()"> <xsl:value-of select="replace(replace(replace(.,'Note:',$NoteBold), 'Before:',$BeforeBold), 'Now:', $NowBold)"/> </xsl:template>
T:\ftemp>type sharon.xml <test> <Row> <ReleaseNote>Before: The application did this. Now: The application does this. 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"> <xsl:copy> <xsl:analyze-string select="." regex="Before:|Note:|Now:"> <xsl:matching-substring> <b><xsl:value-of select="."/></b> </xsl:matching-substring> <xsl:non-matching-substring> <xsl:value-of select="."/> </xsl:non-matching-substring> </xsl:analyze-string> </xsl:copy> </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] Search and Replace to add HTM, Sharon_Harris | Thread | |
[xsl] Search and Replace to add HTM, Sharon_Harris | Date | |
Month |