Tuesday, September 16, 2008

Create Empty Tag in Tranformations

What forced me into it?

The message received from a web service had less data than what the XML (cannonical Data model needed) had. Down the line there were conditions that check the value of a element in the XML. These could be empty or some XYZ value.

Now the transformation had to map these value onto the XML, but if I did not map them the XML will miss the elements.

What I wanted to see?

What I wanted to see was, I should be able to perform the transformation from the Input Variable to the Output Variable.

Those elements that were required should not be lost.
These elements should be as empty tags in the Output Variable.

What did I get?

The transformation lost those elemements that I did not map.
That left me with only a few elements in the Output Variable.
Less than the required elements.

How I fixed this?

First of all I could not change the XML definition as the XMl is shared my a host of systems.
And it would be a massive effort to get this done.

Now a simple work around for this would be to assign a blank to the element in the transformation.

Now if you are think what is that supposed to mean, here is what I mean.
In the transformation right click the element that you dod not want to loose as that is not mapped.
Choose "setText" option in there.
Give a space in the "Text" field that you see there.

Congrats you have done this. Was simple aint it.

What does it look like back there?

Well inthe transaformation it will look like this

<xsl:text disable-output-escaping="no"> </xsl:text>

If you want to try?

If you have noted this, the xsl will have a space between the tags.
Delete that. And see what you get.
I have seen no difference on my instance.

No comments: