cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Mapping - Concat repeating elements

Rakesh-Kr
Explorer
0 Likes
1,219

I need mapping help with the concat:

Source:

<root>
<SomeNode>
   <SomeNode2>
      <textContent>First Text</textContent>
      <textContent>Second Text</textContent>
   </SomeNode2>
</SomeNode>
<SomeNode>
   <SomeNode2>
      <textContent>First Text</textContent>
      <textContent>Second Text</textContent>
   </SomeNode2>
</SomeNode>
</root>

Target:

<root>
<SomeNode>
   <ConcatNode>First Text, Second Text</ConcatNode>
</SomeNode>
<SomeNode>
   <ConcatNode>Third Text, Forth Text</ConcatNode>
</SomeNode>
</root>

How to achieve this?

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Ryan-Crosby
Active Contributor

I'm afraid I don't have the patience to construct XSDs to build a graphical mapping example, but here is an XSLT that will accomplish the job, and it takes much less time to get to the finish line.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:mode on-no-match="shallow-copy"/>
    <xsl:template match="SomeNode2">
        <xsl:copy>
          <ConcatNode><xsl:apply-templates select="textContent"/></ConcatNode>          
        </xsl:copy>
    </xsl:template>

    <xsl:template match="textContent">
      <xsl:choose>
        <xsl:when test="position() != last()">
          <xsl:value-of select="concat(., ', ')"/>
        </xsl:when>
        <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
      </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

 

Regards,

Ryan Crosby

Rakesh-Kr
Explorer
0 Likes
Thank You, I will give it a try.

Answers (2)

Answers (2)

Rakesh-Kr
Explorer
0 Likes

Hi Ryan, I am using the graphical interface in CI. Thanks

Rakesh-Kr
Explorer
0 Likes

Hi Ryan, I am using the graphical mapping interface in CI. Thanks