Using Inline XSLT to Populate an <Any> Element
I have been working recently with schemas containing <Any> elements. Luckily I don’t need to manipulate the <Any> contents much: to do so, the standard BizTalk functoids available in the mapper can’t be used and instead, given the range of the XML that can be expected in the <Any>, some extensive custom XSLT would be required.
I have two scenarios:
- The contents of an <Any> element need to be copied to a known schema “as is”.
- The contents of a known schema need to mapped “as is” to an <Any>.
I struggled with the mass copy functoid for both scenarios – it didn’t behave quite how I expected/wanted.
After a bit of head scratching and a read of this blog post, I realised that the mass copy doesn’t copy across root elements. I suppose, for example, the assumption is that both source and target schemas will contain a common element that can be used as the “target” of the mass copy functoid. This wouldn’t work in my case, since the schemas being mapped are quite different and also the <Any> would contain a range of different XML, so I couldn’t specify an appropriate containing “root” element.
To get around this behaviour of the mass copy functoid, in my map I created a scripting functoid and added some inline XSLT like this:
<xsl:copy-of select=”.” />
My map then looked like this:
Here is an example instance of the source message:
And this is the result after passing the message above through the map:
Also here is the output message if the mass copy functoid is used (note that the root <Order> element is missing, under <Entities>):
It seems strange and limiting that the mass copy functoid doesn’t copy the root element.