Sumathi
Sumathi

Reputation: 83

XSLT - To remove special character

I want to remove special character and space from content,

<litem><para>■ <emph type="bold">Target:</emph> Water</para></litem>
<litem><para>◆ Wound-healing response within the dermis and epidermis via application of heat without creating a traumatic wound</para></litem>

The output would be,

<litem><para><emph type="bold">Target:</emph> Water</para></litem>
<litem><para>Wound-healing response within the dermis and epidermis via application of heat without creating a traumatic wound</para></litem>

I have used this XSLT,

<xsl:output use-character-maps="m1"/>    
<xsl:character-map name="m1">
    <xsl:output-character character="■" string=""/>
    <xsl:output-character character="◆" string=""/>
</xsl:character-map>

While using above xslt, only special character is getting remove, not unwanted spce. I want to remove character with space. Could you please guide us.

Upvotes: 0

Views: 873

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167516

Try <xsl:template match="item/para/text()[1][matches(., '^[■◆]\s*')]"><xsl:value-of select="replace(., '^[■◆]\s*', '')"/></xsl:template> which would only remove any text in the first text() child of para of item if they start with one of those two characters and are followed by optional white space. You might want to adjust the match pattern if you want to have the same effect for other text nodes, but the key is using ^ in the regular expression pattern to indicate to only match the start of a string.

Upvotes: 1

Related Questions