BizTalk Server General - Mapping question -- not sure how to approach this one

This is Interesting: Free IT Magazines  
Home > Archive > BizTalk Server General > April 2006 > Mapping question -- not sure how to approach this one





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 Mapping question -- not sure how to approach this one
cmedin

2006-04-18, 12:46 am

OK, here's what I want to do. Input (not the actual input, but similar
structure):

<Pallet>
<Items>
<Item>
<Reference>0001</Reference>
<Qty>5</Qty>
</Item>
<Item>
<Reference>0001</Reference>
<Qty>5</Qty>
</Item>
<Item>
<Reference>0002</Reference>
<Qty>5</Qty>
</Item>
<Item>
<Reference>0003</Reference>
<Qty>5</Qty>
</Item>
</Items>
</Pallet>
<Pallet>
<Items>
<Item>
<Reference>0001</Reference>
<Qty>5</Qty>
</Item>
<Item>
<Reference>0002</Reference>
<Qty>5</Qty>
</Item>
</Items>
</Pallet>

Now, what I wish to do is map this into the following:
<LineItem>
<Reference>0001</Reference>
<Qty>15</Qty>
</LineItem>
<LineItem>
<Reference>0002/Reference>
<Qty>10/Qty>
</LineItem>
<LineItem>
<Reference>0003/Reference>
<Qty>5</Qty>
</LineItem>

Basically, I want to collect the quantities by Reference and stick into an
output format that has a single Reference segment for each reference #
(0001,0002 etc). The source can have any number of Item segments
referencing the same #, nested in various Pallets... what I can't figure out
is how to create only one Reference entry on the target side.. I figure that
if I can somehow pull a unique Reference out of the source map I could use
some cumulative functoids together with logical Equal to only sum up the
quantities for the given reference.

But I am lost.. help!


thanks,

Christer


WenJun Zhang[msft]

2006-04-18, 12:46 am

Hi Christer,

The built-in functoids are not good at doing this. I think the most
convenent way is writting custom XPath to query and sum the values either
in the map(script functoid) or in your orchestration.

Thanks.

Best regards,

WenJun Zhang
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.



Greg Forsythe

2006-04-18, 12:46 am

Here is a sample custom Xslt as per WenJun's suggestion

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl" version="1.0"
xmlns:ns0="urn:output">
<xsl:output omit-xml-declaration="yes" version="1.0" method="xml" />
<xsl:key name="itemkey" match="/root//Item" use="Reference"/>
<xsl:template match="/">
<xsl:apply-templates select="/root" />
</xsl:template>
<xsl:template match="/root">
<ns0:root>
<xsl:for-each select="//Item">
<xsl:variable name="group" select="key('itemkey', Reference)"/>
<xsl:if test="generate-id($group[1]) = generate-id()">
<LineItem>
<Reference><xsl:value-of select="Reference" /></Reference>
<Qty><xsl:value-of select="sum($group/Qty)"/></Qty>
</LineItem>
</xsl:if>
</xsl:for-each>
</ns0:root>
</xsl:template>
</xsl:stylesheet>

I gave both your example xml fragments a <root> node and the output schema a
targetnamespace of "urn:output"

Greg


""WenJun Zhang[msft]"" <wjzhang@online.microsoft.com> wrote in message
news:WOPdld6XGHA.5540@TK2MSFTNGXA01.phx.gbl...
> Hi Christer,
>
> The built-in functoids are not good at doing this. I think the most
> convenent way is writting custom XPath to query and sum the values either
> in the map(script functoid) or in your orchestration.
>
> Thanks.
>
> Best regards,
>
> WenJun Zhang
> Microsoft Online Partner Support
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
>
>



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com