Skip to Content
avatar image
Former Member

Mapping: Fitting managers into rooms ?

Hello All, The below map is disinclined to acquiesce to my request; translation: itz knot verkin.

I'm trying to fit the 'managers' in the source into 'room's in the target. Assuming a max of 4 rooms, I want them filled up with 4 managers per room (with some rooms remaining empty and not showing up in the target).

I'm learning how to map currently. Thanks for your help.

SOURCE:

<?xml version="1.0" encoding="UTF-8"?>

<ns0:s2 xmlns:ns0="urn://maptest">

<managers>

<personalID>PID001</personalID>

<personalID>PID002</personalID>

<personalID>PID003</personalID>

<personalID>PID004</personalID>

<personalID>PID005</personalID>

<personalID>PID006</personalID>

<personalID>PID007</personalID>

</managers>

</ns0:s2>

MAPPING:

???

After the map runs, the target produced SHOULD look as follows:

TARGET:

<?xml version="1.0" encoding="UTF-8"?>

<ns0:t2 xmlns:ns0="urn://maptest">

<room>

<personalID>PID001</personalID>

<personalID>PID002</personalID>

<personalID>PID003</personalID>

<personalID>PID004</personalID>

</room>

<room>

<personalID>PID005</personalID>

<personalID>PID006</personalID>

<personalID>PID007</personalID>

</room>

</ns0:t2>

In the source, managers is 1..1, while personalID is 0..unbounded.

In the target, room is 0..4, while personalID is 1..4.

Thanks, Bhishma

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 13, 2006 at 04:22 PM

    Refer to the Weblog

    'Message Splitting Using the Graphical Mapping Tool'

    /people/claus.wallacher/blog/2006/06/29/message-splitting-using-the-graphical-mapping-tool

    which will help you to Split the source message.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Henrique, Stefan, John, THANK YOU !

      I have learnt so much in this 1 post; The map is now willing to acquiesce to my request !

      Here's the graphical map:

      /ns0:t2=/ns0:s2=

      /ns0:t2/room=collapseContexts(SplitByValue([type=Value changed]floor(div(index([start=0, inc=1, type=context]/ns0:s2/managers/personalID=), const([value=4])))))

      /ns0:t2/room/personalID=formatByExample(/ns0:s2/managers/personalID=, SplitByValue([type=Value changed]floor(div(index([start=0, inc=1, type=context]/ns0:s2/managers/personalID=), const([value=4])))))

      At this point I have an understanding of contexts & most of the built-in functions. Lots more to learn; let the games begin !

      Ciao, Bhishma

  • Sep 12, 2006 at 04:12 PM

    Dude,

    I'm in the final phase of the project where I don't get much to do, so I spend the whole day studying new stuff. =D

    Your example sure was a hell of an exercise on XSLT.

    Try this mapping on your scenario.

    <?xml version="1.0" encoding="UTF-8"?>

    http://www.w3.org/1999/XSL/Transform" xmlns:ns0="urn://maptest">

    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:param name="managers"/>

    <xsl:template match="/">

    <xsl:param name="managers" select="//personalID"/>

    <ns0:t2>

    <xsl:call-template name="rooms">

    <xsl:with-param name="managers" select="$managers"/>

    </xsl:call-template>

    </ns0:t2>

    </xsl:template>

    <xsl:template name="rooms">

    <xsl:param name="managers"/>

    <xsl:call-template name="add_room">

    <xsl:with-param name="managers" select="subsequence($managers, 1, 4)"/>

    </xsl:call-template>

    <xsl:if test="not(empty(subsequence($managers, 5)))">

    <xsl:call-template name="rooms">

    <xsl:with-param name="managers" select="subsequence($managers, 5)"/>

    </xsl:call-template>

    </xsl:if>

    </xsl:template>

    <xsl:template name="add_room">

    <xsl:param name="managers"/>

    <room>

    <xsl:for-each select="$managers">

    <xsl:copy-of select="."/>

    </xsl:for-each>

    </room>

    </xsl:template>

    </xsl:stylesheet>

    Add comment
    10|10000 characters needed characters exceeded

    • New retry:

      try this ugly-but-possibly-XI-compliant XSLT

      (I didn't test it because I'm at home; will test it tomorrow)

      <?xml version="1.0" encoding="UTF-8"?>

      http://www.w3.org/1999/XSL/Transform" xmlns:ns0="urn://maptest">

      <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

      <xsl:template match="/">

      <ns0:t2>

      <xsl:for-each select="//personalID">

      <xsl:if test="position() mod 4 = 1">

      <xsl:text disable-output-escaping="yes"><![CDATA[<room>]]></xsl:text>

      </xsl:if>

      <xsl:copy-of select="."/>

      <xsl:choose>

      <xsl:when test="position() mod 4 = 0">

      <xsl:text disable-output-escaping="yes"><![CDATA[</room>]]></xsl:text>

      </xsl:when>

      <xsl:otherwise>

      <xsl:if test="position() = last()">

      <xsl:text disable-output-escaping="yes"><![CDATA[</room>]]></xsl:text>

      </xsl:if>

      </xsl:otherwise>

      </xsl:choose>

      </xsl:for-each>

      </ns0:t2>

      </xsl:template>

      </xsl:stylesheet>

      Regards,

      Henrique.

  • Sep 13, 2006 at 08:09 AM

    You can do this with two UDF (cache context):

    public void createRooms(String[] a,ResultList result,Container container){
      for (int k=0; k<(a.length+3)/4; k++)
        result.addValue("");
    }

    public void distibuteManagers(String[] a,ResultList result,Container container){
      for (int k=0;k<a.length;k++){
        result.addValue(a[k]);
        if (k%4==3&&k<a.length)
          result.addContextChange();
      }
    }

    Do the mapping that way:

    personalID - createRooms - room
    personalID - distributeManagers - personalID

    Regards

    Stefan

    Add comment
    10|10000 characters needed characters exceeded