0

I tryng to making a complex mapping (complex to me) with the follow scenario:

In:

<root>
    <bigrow>
        <row>1</row>
        <row>second</row>
        <row>third</row>
    </bigrow>
    <bigrow>
        <row>4</row>
        <row>rowvalue</row>
        <row>anotherrowvalue</row>
    </bigrow>
</root>

Out:

<entities>
    <entity>
        <atributeA>1</atributeA>
        <atributeB>some</atributeB>
        <atributeC>value</atributeC>
    </entity>
    <entity>
        <atributeA>2</atributeA>
        <atributeB>another</atributeB>
        <atributeC>valuee</atributeC>
    </entity>
    <entity>
        <atributeA>3</atributeA>
        <atributeB>ooother</atributeB>
        <atributeC>valueee</atributeC>
    </entity>
</entities>

I want to map the row elements from the entry in order, so the desired result needs to be something like this:

<entities>
    <entity>
        <atributeA>1</atributeA>
        <atributeB>second</atributeB>
        <atributeC>third</atributeC>
    </entity>
    <entity>
        <atributeA>4</atributeA>
        <atributeB>rowvalue</atributeB>
        <atributeC>anotherrowvalue</atributeC>
    </entity>
</entities>

I create the map making the entry and the output as a XML and generating the schemas from this two xml and the dataMapper window looks like that:

https://i.stack.imgur.com/6CYrR.png

I cant find how to make this to work... If somebody can help me on this yuo can make me happy =)

OptimizedQuery
  • 1,262
  • 11
  • 21
Nicolas
  • 370
  • 3
  • 10

1 Answers1

0

Mule comes with an XSL-T transformer so, in case you're interested, here is the transformation that achieves your goal without using the heavy artillery of DataMapper.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/">
    <entities>
      <xsl:apply-templates />
    </entities>
  </xsl:template>

  <xsl:template match="bigrow">
    <entity>
      <atributeA>
        <xsl:value-of select="child::row[position()=1]/text()" />
      </atributeA>
      <atributeB>
        <xsl:value-of select="child::row[position()=2]/text()" />
      </atributeB>
      <atributeC>
        <xsl:value-of select="child::row[position()=3]/text()" />
      </atributeC>
    </entity>
  </xsl:template>
</xsl:stylesheet>
David Dossot
  • 33,403
  • 4
  • 38
  • 72
  • Thanks for your quickly answer, very usefull your XSLT solution! But i want to use the DataMapper because i want to know all the power of the tool to make some comparasions with other products, and this is one of the problems that i want to know if i can solve with the DataMapper and avoid other technologies like XSLT – Nicolas Apr 16 '13 at 18:57
  • Good point. No doubt this is possible with DM. Maybe switch to the scripting view and write the mapping rules with MEL? Hopefully a DM user will chime in and post a definitive answer. – David Dossot Apr 16 '13 at 19:05