Search code examples
xsltbiztalkbiztalk-2010biztalk-mapper

Using a BizTalk map to unescape XML in a particular node


I have the following schema:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://www.RedEyedMonster.co.uk/Integration/ESB" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" elementFormDefault="qualified" targetNamespace="http://www.RedEyedMonster.co.uk/Integration/ESB" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:annotation>
    <xs:appinfo>
      <b:schemaInfo is_envelope="no" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" />
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="ExternalEvent">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="1" name="XmlType" type="xs:string" />
        <xs:element minOccurs="1" maxOccurs="1" name="EscXml" type="xs:string" />
       </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Where EscXml contains escaped XML which can be quite complex. Is it possible to convert this in a map (i.e. unescape) to an node or to the schema that will be derived from XmlType?


Solution

  • Applying this stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="@*|node()">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
      </xsl:template>
      <xsl:template match="*[local-name()='EscXml']">
        <xsl:copy>
            <xsl:value-of select="." disable-output-escaping="yes"/>
        </xsl:copy>
      </xsl:template>
    </xsl:stylesheet>
    

    To this sample document:

    <ExternalEvent xmlns="http://www.RedEyedMonster.co.uk/Integration/ESB">
    <XmlType>Testing1Two6</XmlType>
    <EscXml>&lt;!--  Edited by XMLSpy&#174;  --&gt;
    &lt;note&gt;
    &lt;to&gt;Tove&lt;/to&gt;
    &lt;from&gt;Jani&lt;/from&gt;
    &lt;heading&gt;Reminder&lt;/heading&gt;
    &lt;body&gt;Don&apos;t forget me this weekend!&lt;/body&gt;
    &lt;/note&gt;</EscXml>
    </ExternalEvent>
    

    Gives me the following result – also in BizTalk:

    <?xml version="1.0" encoding="UTF-8"?>
    <ExternalEvent xmlns="http://www.RedEyedMonster.co.uk/Integration/ESB">
       <XmlType>Testing1Two6</XmlType>
       <EscXml>
    
          <!--  Edited by XMLSpy®  -->
    <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
    </note>
    
       </EscXml>
    </ExternalEvent>
    

    Hope this helps :]