Monday, April 14, 2014

Mapping ComplexType mixed=True Node

I was pretty proud of my previous solution to a node that may or may not have embedded html. Until I tried to use BizTalk mapper to map said node. Simply linking the node to the target schema node resulted in just the text before the first embedded element being mapped. Aha, I thought, Mass Copy functoid to the rescue . . . but that resulted in just the embedded elements being copied and NONE of the text. I could not find a solution using functoids, so I turned to the reliable Scripting functoid. The following code in an Inline XSLT Call Template functoid worked:

<xsl:template name="CopyMergedTest">
    <xsl:param name="param1" />
    <xsl:element name="<ElementToCopyTo>">
         <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
<xsl:template match="text()">
    <xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
</xsl:template>

Having the final <xsl:template match="@* | node()"> was necessary to copy the embedded tags.