Flat XML structure to heirarchical XML
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > BizTalk Server > BizTalk Server General > Flat XML structure to heirarchical XML




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Flat XML structure to heirarchical XML  
neubs007@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-14-06 02:59 AM

I have what I thought would be an easy mapping in biztalk.  I must be
overlooking a way to get this done in the mapper.

I have an XML that looks like such.
<Records>
<Record RecordId="1000" OrderNo="1" ItemNo="10" Qty="1" />
<Record RecordId="1001" OrderNo="1" ItemNo="11" Qty="1" />
<Record RecordId="1002" OrderNo="1" ItemNo="12" Qty="2" />
<Record RecordId="1003" OrderNo="1" ItemNo="13" Qty="3" />
<Record RecordId="1004" OrderNo="2" ItemNo="10" Qty="1" />
<Record RecordId="1005" OrderNo="2" ItemNo="11" Qty="1" />
<Record RecordId="1006" OrderNo="3" ItemNo="13" Qty="3" />
</Records>

It needs to be mapped to:
<Orders>
<Order OrderNo="1">
<Item ItemNo="10" Qty="1"/>
<Item ItemNo="11" Qty="1"/>
<Item ItemNo="12" Qty="2"/>
<Item ItemNo="13" Qty="3"/>
</Order>
<Order OrderNo="2">
<Item ItemNo="10" Qty="1"/>
<Item ItemNo="11" Qty="1"/>
</Order>
<Order OrderNo="2">
<Item ItemNo="13" Qty="3"/>
</Order>
</Orders>

If I map them straight across in the mapper, the OrderNo repeats.

My Question is how can I get the "Grouping" functionality applied to a
element/attribute so I can get the desired results.






[ Post a follow-up to this message ]



    Re: Flat XML structure to heirarchical XML  
Tomas Restrepo \(MVP\)


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-17-06 08:03 AM

>I have what I thought would be an easy mapping in biztalk.  I must be
> overlooking a way to get this done in the mapper.
>
> I have an XML that looks like such.
> <Records>
>  <Record RecordId="1000" OrderNo="1" ItemNo="10" Qty="1" />
>  <Record RecordId="1001" OrderNo="1" ItemNo="11" Qty="1" />
>  <Record RecordId="1002" OrderNo="1" ItemNo="12" Qty="2" />
>  <Record RecordId="1003" OrderNo="1" ItemNo="13" Qty="3" />
>  <Record RecordId="1004" OrderNo="2" ItemNo="10" Qty="1" />
>  <Record RecordId="1005" OrderNo="2" ItemNo="11" Qty="1" />
>  <Record RecordId="1006" OrderNo="3" ItemNo="13" Qty="3" />
> </Records>
>
> It needs to be mapped to:
> <Orders>
>  <Order OrderNo="1">
>    <Item ItemNo="10" Qty="1"/>
>    <Item ItemNo="11" Qty="1"/>
>    <Item ItemNo="12" Qty="2"/>
>    <Item ItemNo="13" Qty="3"/>
>  </Order>
>  <Order OrderNo="2">
>    <Item ItemNo="10" Qty="1"/>
>    <Item ItemNo="11" Qty="1"/>
>  </Order>
>  <Order OrderNo="2">
>    <Item ItemNo="13" Qty="3"/>
>  </Order>
> </Orders>
>
> If I map them straight across in the mapper, the OrderNo repeats.
>
> My Question is how can I get the "Grouping" functionality applied to a
> element/attribute so I can get the desired results.

A common way to do this is by using a custom XSLT functoid (or the entire
map) to do the grouping. It's not very "intuitive" how to do it, but it can
be done in XSLT by using xsl:key to force the XSLT engine to sort of query
what available values are for a field, and then for each one do something
(in this case take nodes associated with said value).

Here's an article with an example of how to do it in biztalk:
http://spaces.msn.com/members/jglisson73/Blog/cns!1pbsbLGl_CIJ0qtXR3-XWxXw!2
42.entry

And here's some good information about grouping in XSLT in general:
http://www.dpawson.co.uk/xsl/sect2/N4486.html#d5052e37


--
Tomas Restrepo
tomasr@mvps.org
http://www.winterdom.com/







[ Post a follow-up to this message ]



    Re: Flat XML structure to heirarchical XML  
fischer@sofika.de


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-30-06 10:53 PM

With the xml-tool <xml>cmp (http://www.xmlcmp.com) you can do such a
grouping without writing a program.
You just configure the grouping-rules.

You need a basic-control-file and a toxml-control-file:

Example: basic-control-file: cmp122.xml

<Records>
<Record
ident_att_OrderNo="true"
ident_att_RecordId="true"
ident_att_ItemNo="true"
ident_att_Qty="true"
/>
</Records>

Example: toxml-control-file: toxml122.xml

<Orders>
<Order        ident_att_OrderNo="true"
path_att_OrderNo="/Records/Record/@OrderNo">
<Item ident_att_Qty="true"
path_att_Qty="/Records/Record/@Qty"
ident_att_ItemNo="true"
path_att_ItemNo="/Records/Record/@ItemNo"
/>
</Order>
</Orders>

Executing the grouping:

$ xmltoxml.sh cmp122.xml toxml122.xml test122.xml

<Orders>
<Order OrderNo='1'>
<Item ItemNo='10' Qty='1'>
</Item>
<Item ItemNo='11' Qty='1'>
</Item>
<Item ItemNo='12' Qty='2'>
</Item>
<Item ItemNo='13' Qty='3'>
</Item>
</Order>
<Order OrderNo='2'>
<Item ItemNo='10' Qty='1'>
</Item>
<Item ItemNo='11' Qty='1'>
</Item>
</Order>
<Order OrderNo='3'>
<Item ItemNo='13' Qty='3'>
</Item>
</Order>
</Orders>






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 05:03 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register