Consider a Input Message.
- <ns0:Input attr="attr_0" xmlns:ns0="http://MappingXML.Input">
- <Name>Name_0</Name>
- <age>age_0</age>
- </ns0:Input>
Which need to be mapped to a single node in Output Message,
- <ns0:Output xmlns:ns0="http://MappingXML.output">
- <Existing>Existing_0</Existing>
- <SourceXML>Source XML Message comes Here</SourceXML>
- </ns0:Output>
so that the Output Message would look like,
- <ns0:Output xmlns:ns0="http://MappingXML.output">
- <Existing>abc</Existing>
- <SourceXML>
- <ns0:Input attr="attr_0" xmlns:ns0="http://MappingXML.Input">
- <Name>Name_0</Name>
- <age>age_0</age>
- </ns0:Input>
- </SourceXML>
- </ns0:Output>
You can achieve it using a custom XSLT map, as described below.
- <?xml version="1.0" encoding="UTF-16"?>
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0 userCSharp" version="1.0" xmlns:ns0="http://MappingXML.output" xmlns:s0="http://MappingXML.Input" xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp">
- <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
- <xsl:template name="identity" match="@* | node()">
- <xsl:copy>
- <xsl:apply-templates select="@* | node()"/>
- </xsl:copy>
- </xsl:template>
- <xsl:template match="/s0:Input">
- <ns0:Output>
- <Existing>Something</Existing>
- <xsl:element name="SourceXML">
- <xsl:call-template name="identity" />
- </xsl:element>
- </ns0:Output>
- </xsl:template>
- </xsl:stylesheet>
here we are creating a XSL template "identity" which copies the entire message to the place where template is called.
<xsl:call-template name="identity" />above line calls the template written at line number 12 to 14, which creates the element "SourceXML" and then calls the template.
<xsl:element name="SourceXML">
<xsl:call-template name="identity" />
</xsl:element>
Line number 10 to 15 is used to create the Output Message structure in the Output XML. you can add all the nodes you require in output message here,
<ns0:Output>
<Existing>Something</Existing>
<xsl:element name="SourceXML">
<xsl:call-template name="identity" />
</xsl:element>
</ns0:Output>
If you face problem in creating the other part of the XSLT map, then you can generate it by following the below steps,
- Create a map in Biztalk,
- Map the source and destination schema, but don't create any link.
- Debug the map, Visual studio automatically creates an XSL sheet for the map which you can save and edit it as per your requirements.