Friday, November 18

Convert xml file to string inside BizTalk map using inline XSLT

I have a love for BizTalk maps because of their speed and the obvious load benefits when compared against orchestrations. I am therefore always pushing myself to find solutions that will avoid the use of orchestrations as much as possible when building applications. Inline XSLT is proven as one of the fastest methods for map conversions

One such endeavour led me to this solution. This solution allows you to convert a whole xml message into a string and feed it into one string node which can then be used in another map which (for whatever reason) may require a string message version of your original xml message. This could be done in an expression shape and message assignment shape in an orchestration, but as I said above, if you can avoid the load, why not?

  1. Create a schema with a root node and a child field element node of string Data Type
  2. Create a map which references your schema(s)
  3. Add the xml schema to be converted as the source schema of your map
  4. Add the new schema as the destination schema
  5. Add a scripting functoid to the map
  6. Connect the Root node of the source schema and the string data type (not the root) node of the source schema
  7. Configure the scripting functoid (right-click, configure functoid script, Script functoid configuraiton) and choose Inline XSLT Call Ttemplate
  8. Add the following script to the functoid: <xsl:template name="xml-to-string-called-template">
       <xsl:param name="param1" />
              <xsl:element name="ns0:NameofNodetoHoldString">
                    <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
                    <xsl:call-template name="identity" />
                    <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
               </xsl:element>
    </xsl:template>
    <xsl:template name="identity" match="@*|node()">
       <xsl:copy>
    <xsl:apply-templates select="@*|node()" />
       </xsl:copy>
     </xsl:template>
  9. Test the map, and your whole source xml would have been nicely converted into a string and added  into the string node within the CDATA! section (which tells the processing receiver that everything within those should be treated as strings)



No comments:

Post a Comment