Friday, July 15, 2011

Checking if the optional element exists or not in Mapping

Charan: I have a problem I have one schema which has one optional filed 'Element1' and I need to map this schema to other schema but the twist is if this optional filed is not present in the input schema then I need to map other filed 'Element2' to the output schema.
 Input schema with optional filed 'Element1'

 Output Schema

Rohit: You can do this using the Scripting functoid as shown below:
 Drag scripting functoid

 Configure scripting functoid

Following is the XSLT used for scripting functoid.
<Element xmlns:p="http://CheckNodeExistenceInMap.InputSchema_XML">
    <xsl:choose>
        <xsl:when test="/p:Record/Element1">
            <xsl:value-of select="/p:Record/Element1" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="/p:Record/Element2" />
        </xsl:otherwise>
    </xsl:choose>
</Element>

Note: If the value of property 'Element FormDefault' for the source schema is 'Qualified' then the alias for namespace need to be used for each element as mentioned below:

<Element xmlns:p="http://CheckNodeExistenceInMap.InputSchema_XML">
    <xsl:choose>
        <xsl:when test="/p:Record/p:Element1">
            <xsl:value-of select="/p:Record/p:Element1" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="/p:Record/p:Element2" />
        </xsl:otherwise>
    </xsl:choose>
</Element> 



Cheers
Rohit Sharma

1 comment:

Monil Jain said...

Hi rohit I have come across such problem and I have followed ur xslt.. I am trying to assign the value 0 if the source record doesn't exists. I am getting the output as 0.. But it's giving 0 even when the record exists

Post a Comment