マッピングを設定
ファンクションを使い、ストラクチャーで実行する変換を定義します。
次の例は複雑なマッピングパターンをいくつか表したものです。
ネスト化されたループを単純なループに結合
ネスト化されたループを結合させることで、ネスト化されたループを持つXMLストラクチャーをフラットなCSVストラクチャーに変換します。
Before you begin
About this task
この例では、入力XMLファイルには発注書に関する情報が含まれています。各AddressエレメントにはItemsエレメントが含まれており、これにはItemエレメントが少なくとも1つ含まれています。変換の目標は、それぞれのItemについて行があるCSVファイルを用意することです。各行には関連する配送先情報も含まれている必要があります。
この例では、入力として次のXMLサンプルを使います:
<PurchaseOrderShipping PurchaseOrderNumber="99503" OrderDate="2011-03-15T12:10:03+05:30">
<ShipDate>2011-04-30T23:50:00+05:30</ShipDate>
<Address>
<Name>Deandre King</Name>
<Street>4894 Winding Way</Street>
<City>Southfield</City>
<State>MI</State>
<Zip>48075</Zip>
<Country>USA</Country>
<DeliveryNotes>Please leave packages in shed by driveway.</DeliveryNotes>
<Items>
<Item PartNumber="872-AA">
<ProductName>Lawnmower</ProductName>
<Quantity>1</Quantity>
<USPrice>148.95</USPrice>
<Comment>Confirm this is electric</Comment>
</Item>
<Item PartNumber="926-AA">
<ProductName>Baby Monitor</ProductName>
<Quantity>2</Quantity>
<USPrice>39.98</USPrice>
</Item>
</Items>
</Address>
<Address>
<Name>Burl Clark</Name>
<Street>3807 Pointe Lane</Street>
<City>Fort Lauderdale</City>
<State>FL</State>
<Zip>33308</Zip>
<Country>USA</Country>
<Items>
<Item PartNumber="356-KX">
<ProductName>Gas canister</ProductName>
<Quantity>1</Quantity>
<USPrice>123.02</USPrice>
</Item>
</Items>
</Address>
</PurchaseOrderShipping>
出力ストラクチャーは以下のように定義されています:
ItemsShipping
item (0:*)
PurchaseOrderNumber
ShipTo
ShipDate
PartNumber
ProductName
Quantity
USPrice
Procedure
Results
PurchaseOrderNumber,ShipTo,ShipDate,PartNumber,ProductName,Quantity,USPrice
99503,Deandre King 4894 Winding Way Southfield MI 48075 USA,2011-04-30T23:50:00+05:30,872-AA,Lawnmower,1,148.95
99503,Deandre King 4894 Winding Way Southfield MI 48075 USA,2011-04-30T23:50:00+05:30,926-AA,Baby Monitor,2,39.98
99503,Burl Clark 3807 Pointe Lane Fort Lauderdale FL 33308 USA,2011-04-30T23:50:00+05:30,356-KX,Gas canister,1,123.02
ネスト化されたループを単純なループに集計
ネスト化されたループを集計することで、ネスト化されたループを持つXMLストラクチャーをフラットなCSVストラクチャーに変換します。
Before you begin
About this task
この例では、ネスト化されたループを単純なループに結合と同じ入力ストラクチャーが使用されています。この変換の目標は、各Addressエレメントに配送と製品に関する情報が含まれている行を持つCSVファイルを作成することです。
住所に配送されるすべての製品が各行に含まれるよう、出力ストラクチャーには複数のPartNumberエレメントとProductNameエレメントが含まれています。次のように定義されています:
AddressesShipping
Address (0:*)
Name
Street
City
State
Zip
Country
DeliveryNotes
PartNumber_1
ProductName_1
PartNumber_2
ProductName_2
PartNumber_3
ProductName_3
Procedure
Results
Name,Street,City,State,Zip,Country,DeliveryNotes,PartNumber_1,ProductName_1,PartNumber_2,ProductName_2,PartNumber_3,ProductName_3
Deandre King,4894 Winding Way,Southfield,MI,48075,USA,Please leave packages in shed by driveway.,872-AA,Lawnmower,926-AA,Baby Monitor,,
Burl Clark,3807 Pointe Lane,Fort Lauderdale,FL,33308,USA,,356-KX,Gas canister,,,,