Search code examples
regexxmlxsltxslt-2.0

XSLT - Select content between two special characters


I have a xml like this,

<doc>
    <p>text1 &lt;xml version="1.0" encoding="UTF-16"
        standalone="yes"?&gt; text2</p>
</doc>

I need to remove the text content between &lt; and &gt; form above text using XSLT. So expected output is,

<doc>
    <p>text1 text2</p>
</doc>

I tried to use regex but I'm wondering how I can catch text between &lt; and &gt; form regex.

Any idea how I can do this using XSLT?


Solution

  • This Should Work.

    (&lt;(?:.?\n?)*&gt;)
    

    Then Replace with "" (empty)

    Input:

    <doc>
        <p>text1 &lt;xml version="1.0" encoding="UTF-16"
            standalone="yes"?&gt; text2</p>
    </doc>
    

    Output:

    <doc>
        <p>text1  text2</p>
    </doc>
    

    See: https://regex101.com/r/0o9hol/1