‎2008 Feb 13 9:10 PM
Hello all,
I am having problems with the simple transformation I wrote. Below is a small part of my transformation:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined">
<tt:root name="SDNENTRY" type="ddic:ZOFAC_SDN_ENTRY"/>
<tt:root name="PUBLISHINFORMATION" type="ddic:ZOFAC_PUBLISHINFO_STR"/>
<tt:template>
<sdnList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/sdnList.xsd">
<publshInformation>
<Publish_Date tt:value-ref="PUBLISHINFORMATION.PUBLISH_DATE"/>
<Record_Count tt:value-ref="PUBLISHINFORMATION.RECORD_COUNT"/>
</publshInformation>
<tt:loop ref=".SDNENTRY">
<sdnEntry>
<uid tt:value-ref="SDN_ID"/>
<firstName tt:value-ref="FIRST_NAME"/>
<lastName tt:value-ref="LAST_NAME"/>
<title tt:value-ref="TITLE"/>
<sdnType tt:value-ref="SDN_TYPE"/>
</sdnEntry>
The problem that I am having is that certain elements of the XML file are optional and will not be supplied. XML Example:
<sdnEntry>
<uid>737</uid>
<firstName>John</firstName>
<lastName>Doe</lastName>
<sdnType>Individual</sdnType>
</sdnEntry>
In the above example, title is not given. If I run my program I get an XML Matching Error because it expected title, but read sdnType.
How do I write my transformation so that if the element is not supplied it will just move on to the next element?
Thank you very much. Let me know if more info is needed!
‎2008 Feb 14 4:27 PM
Problem solved.
Used a <tt:cond check> in my tranformation. See below:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined">
<tt:root name="SDNENTRY" type="ddic:ZOFAC_SDN_ENTRY"/>
<tt:root name="PUBLISHINFORMATION" type="ddic:ZOFAC_PUBLISHINFO_STR"/>
<tt:template>
<sdnList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/sdnList.xsd">
<publshInformation>
<Publish_Date tt:value-ref="PUBLISHINFORMATION.PUBLISH_DATE"/>
<Record_Count tt:value-ref="PUBLISHINFORMATION.RECORD_COUNT"/>
</publshInformation>
<tt:loop ref=".SDNENTRY">
<sdnEntry>
<uid tt:value-ref="SDN_ID"/>
<firstName tt:value-ref="FIRST_NAME"/>
<lastName tt:value-ref="LAST_NAME"/>
<tt:cond check="not-initial(TITLE)">
<title tt:value-ref="TITLE"/>
</tt:cond>
<sdnType tt:value-ref="SDN_TYPE"/>
</sdnEntry>
Thank You.