Building an xml with XMLTemplater transformer, some attributes are lists where some element may not exist.
For example, I have contact information for 3 organizations and some may not have an individual name:
contact{0}.CI_ResponsibleParty.organisationName.CharacterString
contact{0}.CI_ResponsibleParty.individualName.CharacterString
contact{0}.CI_ResponsibleParty.contactInfo.CI_Contact.phone.CI_Telephone.voice.CharacterString
contact{1}.CI_ResponsibleParty.organisationName.CharacterString
contact{1}.CI_ResponsibleParty.contactInfo.CI_Contact.phone.CI_Telephone.voice.CharacterString
contact{2}.CI_ResponsibleParty.organisationName.CharacterString
contact{2}.CI_ResponsibleParty.individualName.CharacterString
contact{2}.CI_ResponsibleParty.contactInfo.CI_Contact.phone.CI_Telephone.voice.CharacterString
To populate the xml with a contact block for each organization I do this:
{let $individualName := fme:get-list-attribute("contact{}.CI_ResponsibleParty.individualName.CharacterString")
let $voice := fme:get-list-attribute("contact{}.CI_ResponsibleParty.contactInfo.CI_Contact.phone.CI_Telephone.voice.CharacterString")
for $organisationName at $i in fme:get-list-attribute("contact{}.CI_ResponsibleParty.organisationName.CharacterString")
return
<gmd:contact>
<gmd:CI_ResponsibleParty>
<gmd:individualName>
<gco:CharacterString>{$individualName{$i]}</gco:CharacterString>
</gmd:individualName>
<gmd:organisationName>
<gco:CharacterString>{$organizationName;$i]}</gco:CharacterString>
</gmd:organisationName>
<gmd:contactInfo>
<gmd:CI_Contact>
<gmd:phone>
<gmd:CI_Telephone>
<gmd:voice>
<gco:CharacterString>{$voiceC$i]}</gco:CharacterString>
</gmd:voice>
</gmd:CI_Telephone>
</gmd:phone>
</gmd:CI_Contact>
</gmd:contactInfo>
</gmd:CI_ResponsibleParty>
</gmd:contact>
}
But $individualName is empty if any element in the list is missing so no organization gets the contact\\CI_ResponsibleParty\\individualName\\CharacterString node populated.
Any idea?
There's a NullAttributeMapper transformer to map missing attributes but I have many lists with multiple elements (some of them are nested lists) so I'll need quite a bunch of transformers. There must be some other way.