for 式を使用すると、Mapping ノード内で集約関数の引数として特定の計算を実行できます。
For 式
特定の演算を実行するために、XPath for 式の反復機能を使用できます。
詳しくは、
for expressionオンライン資料を参照してください。
for $i in $source/inventory/category/product return $i/price * $i/quantity
戻り式のすべてのオペランド (price および quantity) が同じ反復可能コンテナー (product) で定義されている場合、同様の式を使用することができます。 for 式では 1 つの変数のみ必要とされます。for $i in $db:select, $j in $source/inventory/category/product
[$i.db1.sch2.PRICE_TB.PROD_ID=$j/product_id]
return $i.db1.sch2.PRICE_TB.PRICE * $j/quantity
戻り式のいくつかのオペランド (price) がデータベース表に保持されており、それ以外のオペランド (quantity) がメッセージに保持されている場合、同様の式を使用することができます。 データベース結果セットへのパスには少なくとも 1 つの変数が必要で、反復可能 XML エレメントへのパスには別の変数が必要です。for $i in $source/order_info/product1, $j in $source/price_record/product2
[$i/product_id=$j/product_id] return $i/quantity * $j/price
オペランド (price および quantity) がソース・メッセージの別の反復可能エレメント (product1 およびproduct2) で定義されている場合、同様の式を使用することができます。項目のシーケンスを表す式がある場合、for 式を集約関数の引数として使用して集約を実行することができます。
fn:avg(for $i in $source/inventory/category/product
return $i/price * $i/quantity)
fn:sum(for $i in $db:select, $j in $source/inventory/category/product
[$i.db1.sch2.PRICE_TB.PROD_ID=$j/product_id]
return $i.db1.sch2.PRICE_TB.PRICE * $j/quantity)
fn:max(for $i in $source/inventory/category/product
return esql:length($i/id))
fn:min(for $i in $source/inventory/category/product
return xs:decimal($i/price))
WebSphere® Message Broker サポートされる集約関数は、for 式を使用して表現できます。
fn:sum($source/inventory/category/product/price)
この式は、次の式と同等です。fn:sum(for $i in $source/inventory/category/product
return $i/price)