Home > Net >  How to remove rich text field tags in xslt <span>, <p> etc
How to remove rich text field tags in xslt <span>, <p> etc

Time:02-18

I have value coming as

<sf:pitch>&lt;p>&lt;span style="color: rgb(68, 68, 68);">https://PPsdfgndgnlksdnflksklenrgkdngldsfklsndfg.com.au&lt;/span>&lt;/p> </sf:pitch>

and I want the output to be like and remove every "p", "span" and non text stripped from the SF:pitch value.

https://PPsdfgndgnlksdnflksklenrgkdngldsfklsndfg.com.au

I have put the code to remove <p> but I want a generic code to remove any tag from the value.

Code which I used to remove <p> is

<xsl:value-of select="substring-before(substring-after(*:Envelope/*:Body/*:retrieveResponse/*:result/*:pitch, '&lt;p&gt;'), '&lt;/p&gt;')" disable-output-escaping="yes"/>

CodePudding user response:

You say:

I want a generic code to remove any tag from the value

But there aren't any "tags" in the value of sf:pitch; it's all a single string containing some escaped markup. Unless you convert the string to XML first (using either XSLT 3.0 or a separate transformation that disables the escaping) and process it as such, you must process it using string manipulation - which is difficult and error-prone.

Perhaps you could do something like:

<xsl:value-of select="replace($string, '.*&gt;([^&lt;] )&lt;.*', '$1')" />

where $string is the sf:pitch element in your example.

But overall, this is not a good approach - see here why.

CodePudding user response:

<xsl:template match="sf:pitch">
  <xsl:value-of select="text()"/>
</xsl:template>

But you have not stated whether it is every sf:pitch or any other possible variations.

  • Related