BizTalk Server General - Flat XML structure to heirarchical XML

This is Interesting: Free IT Magazines  
Home > Archive > BizTalk Server General > January 2006 > Flat XML structure to heirarchical XML





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Flat XML structure to heirarchical XML
neubs007@gmail.com

2006-01-13, 9:59 pm

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.

Tomas Restrepo \(MVP\)

2006-01-17, 3: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!242.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/


fischer@sofika.de

2006-01-30, 5: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>

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com