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

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"/>


Solution 1:[1]

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.

Solution 2:[2]

If you have access to the fn:parse-xml() function, or a similar extension function, then use string(parse-xml(text())). That's assuming the content is well-formed XML. Alternatives are parse-xml-fragment() or parse-html()

Solution 3:[3]

<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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Michael Kay
Solution 3 Kevin Brown