Search code examples
xmlxsltxpathautomationcdata

How to convert lt and gt type values into XML format


I am getting output like this from SOAP response. I need to convert output like this "&lt;CLIOutput&gt;" to <CLIOutput>

Please suggest how to convert it into XML. Can this be done anyway with the help of XPath, XSLT or XML.

<output>
            <line index="1">&lt;CLIOutput&gt;</line>
            <line index="2">  &lt;Results&gt;</line>
            <line index="3">    &lt;ReturnCode&gt;0&lt;/ReturnCode&gt;</line>
            <line index="4">    &lt;EventCode&gt;23000&lt;/EventCode&gt;</line>
            <line index="5">    &lt;EventSummary&gt;CLI command completed successfully.&lt;/EventSummary&gt;</line>
            <line index="6">  &lt;/Results&gt;</line>
            <line index="7">  &lt;Data&gt;</line>
            <line index="8">    &lt;Row&gt;</line>
            <line index="9">      &lt;Tag&gt;cp.20191028151231&lt;/Tag&gt;</line>
            <line index="10">      &lt;Time&gt;2019-10-28 11:12:31 EDT&lt;/Time&gt;</line>
            <line index="11">      &lt;Validated&gt;Validated&lt;/Validated&gt;</line>
            <line index="12">      &lt;Deletable&gt;No&lt;/Deletable&gt;</line>
            <line index="13">    &lt;/Row&gt;</line>
            <line index="14">    &lt;Row&gt;</line>
</output>

Solution

  • You can use disable-output-escaping="yes" to convert the code like below:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        exclude-result-prefixes="#all"
        version="1.0">
    
      <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    
      <xsl:template match="line">
          <xsl:value-of select="." disable-output-escaping="yes"/>
      </xsl:template>
    
    </xsl:stylesheet>
    

    See link: https://xsltfiddle.liberty-development.net/bFWR5E6