I have this function:
CREATE FUNCTION [dbo].[udf_StripHTML]
(@HTMLText VARCHAR(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @Start INT
DECLARE @End INT
DECLARE @Length INT
SET @Start = CHARINDEX('<',@HTMLText)
SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText))
SET @Length = (@End - @Start) + 1
WHILE @Start > 0
AND @End > 0
AND @Length > 0
BEGIN
SET @HTMLText = STUFF(@HTMLText,@Start,@Length,'')
SET @Start = CHARINDEX('<',@HTMLText)
SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText))
SET @Length = (@End - @Start) + 1
END
RETURN LTRIM(RTRIM(@HTMLText))
END
I need to strip everything EXCEPT <em> and <strong> tags.
Thank you
Thomas
xslt transformation via clr function (eg, the one from the MDS assembly)
Update
Here’s the answer using the XSLT transformation approach: How to remove all tags except for some using Nokogiri
Update 2
Then the only option left is to use regular expressions. Again via CLR function.
Strip all HTML tags except links
Installation of the MDS assembly
Deploy SQL 2008 R2 MDS Functions without MDS