Wednesday, May 25, 2011

Conditional mapping in an XSLT in WID

In this tutorial we want to map a value only if it is not empty. If it is empty, we want to use another value.

The input data of our datamap will have 2 fields: cban and iban.  If the iban field is empty, use cban.

Drag a connection from the iban field to the bankaccount field (our target). Change the "move" to "if"



Click in the little blue box of your transformation and make sure you see the Properties view of your transformation. In the Condition tab of the properties, enter the following expression:

$iban!= ''

This states this transformation will only be executed if the iban field does not equal an empty string. Now to define the actual transformation, we need to click the "If" in the blue box of the transformation. This will open a new transformation editor, where you can specify that the iban field should be copied tot the  bankaccount field.





Now how  do we add the "else" clause? Hover your mouse over the blue box of our conditional transformation again (you can reach it by clicking XSLTransformation1_req_1 as seen in the screenshot above).
The first icon will create a new condition (else if), the second one an else.  Click on the "else" icon.
You will see a new blue box appearing beneath your "if" box. This new "else" box needs to be connected as well. Connect the icban value to the "else" box, and the "else" box to the bank account. Also create an actual mapping by clicking on the "else" word.



Regenerate xsl resources in WID

As an update to my post about the xsl resources that could not be found, the generation of xsl mapping files seems even more stubborn than I first thought. The xsl file is indeed generated when the map is tested, but it does not change after you change your actual mapping in the editor. If you test the map again, the previously generated file is used. Even at runtime this is the case.

The one way to regenerate the xsl file for sure is to right-click on the mapping editor, and click "Generate XSLT" (or use the keyboard shortcut Ctrl+Shift+G)