Link to home
Start Free TrialLog in
Avatar of itinfserv

asked on

xslt 1.0 replace text

I use the suggestion from ticket 24821667 on how to replace text with xslt 1.0, the problem it removes html code without me specifing it in the text to replace. any idea why?
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Maybe you need to post both XSLT and XML as attachments.
Without further specification we don't know what is wrong

Note that this works on text replacements,
your HTML tags likely are gone because that are element nodes who are not copied
Avatar of itinfserv


I use the following template to replace a string
        <xsl:template name="replace-str">
            <xsl:param name="str"/>
            <xsl:param name="find"/>
            <xsl:param name="replace"/>
                <xsl:when test="contains($str, $find)">
                    <xsl:value-of select="substring-before($str, $find)"/>
                    <xsl:value-of select="$replace"/>
                    <xsl:call-template name="replace-str">
                        <xsl:with-param name="str" select="substring-after($str, $find)"/>
                        <xsl:with-param name="find" select="$find"/>
                        <xsl:with-param name="replace" select="$replace"/>
                    <xsl:value-of select="$str"/>

Open in new window

and I try to replace the code for this XML, this is only portion of the XML
 directory. Please email amendments to your entry in the 
 to Oracle. Useful number: IS Service Desk: 012 2182 

Open in new window

The problem when I used the template all the <b> and <br> was scraped.
I need more of your XSLT
As I allready expressed earlier seems indeed to be the cause of this problem

If you pass the content of S to the named template,
all the text nodes will be concatenated and sent in the replace functionality
and you loose all the <b>

what you need to do is apply-templates for all nodes at the S level
and call the replacing functionality on both S/text() as S/b/text()

If you post more of your XSLT (maybe the template for S)
I can fix it
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial