This is a straightforward mapping if you use xslt
- look here to convert your map to xslt
.
For example:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/xml">
<xsl:if test="InternalNotes or ExternalNotes">
<!-- . and newline delimiter if both elements present, else none -->
<xsl:variable name="delimiter">
<xsl:if test="InternalNotes and ExternalNotes">. </xsl:if>
</xsl:variable>
<Comments>
<Name>Comments</Name>
<Operation>Append</Operation>
<Value>
<xsl:value-of select="concat(InternalNotes/Value/text(),
$delimiter, ExternalNotes/Value/text())"/>
</Value>
</Comments>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
This converts the following:
<xml>
<ExternalNotes>
<Value>External notes value</Value>
</ExternalNotes>
<InternalNotes>
<Value>Internal notes value</Value>
</InternalNotes>
</xml>
To this:
<?xml version="1.0" encoding="utf-8"?>
<Comments>
<Name>Comments</Name>
<Operation>Append</Operation>
<Value>Internal notes value.
External notes value</Value>
</Comments>
You haven't mentioned what the output should look like with no matches, but you'll obviously at least need a root element. More elegant xslt solutions are possible, I'm sure, but you get the idea :)