mapping/xslt challenge - grouping, key

The3rdNipple

New Member
We have a bit tricky mapping requirements. I am working on converting an incoming xml from one form to another in BizTalk application using BizTalk mapper. The solution can be done using XSLT or built in BizTalk functoids.Source schema looks something like this:\[code\]<?xml version="1.0" encoding="utf-16"?><xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://BizTalkTestProject.SourceSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://BizTalkTestProject.SourceSchema"> <xs:element name="Coverages"> <xs:complexType> <xs:sequence> <xs:element name="Coverage" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="Category" type="xs:string"/> <xs:element name="BillingChargeType" type="xs:string"/> <xs:element name="ASLCode" type="xs:string"/> <xs:element name="EffectiveDate" type="xs:string"/> <xs:element name="DeltaAmount" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element></xs:schema>\[/code\]Destination schema looks something like this:\[code\]<?xml version="1.0" encoding="utf-16"?><xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://BizTalkTestProject.DestinationSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://BizTalkTestProject.DestinationSchema"> <xs:element name="Categories" type="CategoriesType"/> <xs:complexType name="CategoriesType"> <xs:sequence> <xs:element name="Premium" type="CommonElementsType" maxOccurs="unbounded"/> <xs:element name="Tax" type="CommonElementsType" maxOccurs="unbounded"/> <xs:element name="Fee" type="CommonElementsType" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name="CommonElementsType"> <xs:sequence> <xs:element name="CategoryDetail" type="CategoryDetailType" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name="CategoryDetailType"> <xs:sequence> <xs:element name="Type" type="xs:string"/> <xs:element name="AnnualStatementLine" type="xs:string"/> <xs:element name="Amount" type="xs:string"/> <xs:element name="ChangeEffectiveDate" type="xs:string"/> </xs:sequence> </xs:complexType></xs:schema>\[/code\]Sample incoming xml data:\[code\] <ns0:Coverages xmlns:ns0="http://BizTalkTestProject.SourceSchema"> <Coverage> <Category>premium</Category> <BillingChargeType>premium BillingChargeType 2</BillingChargeType> <ASLCode>premium ASLCode 2</ASLCode> <EffectiveDate>2002-02-02</EffectiveDate> <DeltaAmount>22.00</DeltaAmount> </Coverage> <Coverage> <Category>premium</Category> <BillingChargeType>premium BillingChargeType 1</BillingChargeType> <ASLCode>premium ASLCode 1</ASLCode> <EffectiveDate>2001-01-01</EffectiveDate> <DeltaAmount>11.00</DeltaAmount> </Coverage> <Coverage> <Category>premium</Category> <BillingChargeType>premium BillingChargeType 1</BillingChargeType> <ASLCode>premium ASLCode 2</ASLCode> <EffectiveDate>2001-01-01</EffectiveDate> <DeltaAmount>121.00</DeltaAmount> </Coverage> <Coverage> <Category>premium</Category> <BillingChargeType>premium BillingChargeType 1</BillingChargeType> <ASLCode>premium ASLCode 1</ASLCode> <EffectiveDate>2002-02-02</EffectiveDate> <DeltaAmount>112.00</DeltaAmount> </Coverage> <Coverage> <Category>premium</Category> <BillingChargeType>premium BillingChargeType 3</BillingChargeType> <ASLCode>premium ASLCode 3</ASLCode> <EffectiveDate>2003-03-03</EffectiveDate> <DeltaAmount>33.00</DeltaAmount> </Coverage> <Coverage> <Category>premium</Category> <BillingChargeType>premium BillingChargeType 1</BillingChargeType> <ASLCode>premium ASLCode 1</ASLCode> <EffectiveDate>2001-01-01</EffectiveDate> <DeltaAmount>5.00</DeltaAmount> </Coverage> <Coverage> <Category>tax</Category> <BillingChargeType>tax BillingChargeType 4</BillingChargeType> <ASLCode>tax ASLCode 4</ASLCode> <EffectiveDate>2004-04-04</EffectiveDate> <DeltaAmount>44.00</DeltaAmount> </Coverage> <Coverage> <Category>tax</Category> <BillingChargeType>tax BillingChargeType 5</BillingChargeType> <ASLCode>tax ASLCode 5</ASLCode> <EffectiveDate>2005-05-05</EffectiveDate> <DeltaAmount>55.00</DeltaAmount> </Coverage> <Coverage> <Category>fee</Category> <BillingChargeType>fee BillingChargeType 6</BillingChargeType> <ASLCode>fee ASLCode 6</ASLCode> <EffectiveDate>2006-06-06</EffectiveDate> <DeltaAmount>66.00</DeltaAmount> </Coverage></ns0:Coverages>\[/code\]Expected output xml should looks like this:\[code\] <ns0:Categories xmlns:ns0="http://BizTalkTestProject.DestinationSchema"> <Premium> <CategoryDetail> <Type>premium BillingChargeType 2</Type> <AnnualStatementLine>premium ASLCode 2</AnnualStatementLine> <Amount>22.00</Amount> <ChangeEffectiveDate>2002-02-02</ChangeEffectiveDate> </CategoryDetail> <CategoryDetail> <Type>premium BillingChargeType 1</Type> <AnnualStatementLine>premium ASLCode 1</AnnualStatementLine> <Amount>16.00</Amount> <ChangeEffectiveDate>2001-01-01</ChangeEffectiveDate> </CategoryDetail> <CategoryDetail> <Type>premium BillingChargeType 1</Type> <AnnualStatementLine>premium ASLCode 2</AnnualStatementLine> <Amount>121.11</Amount> <ChangeEffectiveDate>2001-01-01</ChangeEffectiveDate> </CategoryDetail> <CategoryDetail> <Type>premium BillingChargeType 1</Type> <AnnualStatementLine>premium ASLCode 1</AnnualStatementLine> <Amount>112.22</Amount> <ChangeEffectiveDate>2002-02-02</ChangeEffectiveDate> </CategoryDetail> <CategoryDetail> <Type>premium BillingChargeType 3</Type> <AnnualStatementLine>premium ASLCode 3</AnnualStatementLine> <Amount>33.00</Amount> <ChangeEffectiveDate>2003-03-03</ChangeEffectiveDate> </CategoryDetail> </Premium> <Tax> <CategoryDetail> <Type>tax BillingChargeType 4</Type> <AnnualStatementLine>tax ASLCode 4</AnnualStatementLine> <Amount>44.00</Amount> <ChangeEffectiveDate>2004-04-04</ChangeEffectiveDate> </CategoryDetail> <CategoryDetail> <Type>tax BillingChargeType 5</Type> <AnnualStatementLine>tax ASLCode 5</AnnualStatementLine> <Amount>55.00</Amount> <ChangeEffectiveDate>2005-05-05</ChangeEffectiveDate> </CategoryDetail> </Tax> <Fee> <CategoryDetail> <Type>fee BillingChargeType 6</Type> <AnnualStatementLine>fee ASLCode 6</AnnualStatementLine> <Amount>66.00</Amount> <ChangeEffectiveDate>2006-06-06</ChangeEffectiveDate> </CategoryDetail> </Fee></ns0:Categories>\[/code\]The mapping requirements are:1. If Category element from source xml has value
 
Back
Top