Note: you can find all mapping logic of this exercise in the forum, however briefly we have a repeating node “TimeSeries” and based on Path attribute value of “TimeSeries” node we will map on some elements of the output message:
<
GetPIArchiveDataResult
>
TimeSeries
xsi:type
=
"TimeSeriesUpdates"
Path
"1"
ErrDesc
""
Error
"-2147220478"
SeriesID
TimedValues
TimedValue
Flags
"Flags_1"
Time
"1999-05-31T13:20:00.000-05:00"
UOM
"UOM_3"
Status
"Status_4"
PctGood
"10"
DataType
"DataType_6"
>2458.25</
</
Updates
></
"2"
>3458.25</
"3"
><
>4458.25</
"4"
>5458.25</
ns0:Req
xmlns:ns0
"http://SQLPollingLearnings.SCMReq"
Quantity
NRJQuantity
AvgCal
AvgDens
if(Path=="1") then assign the value of TimedValue Node to Quantity Node if(Path=="2") then assign the TimedValue to NRJQuantity if(Path=="3") then assign the TimedValue to AvgCal if(Path=="4") then assign the TimedValue to AvgDens
then assign the value of TimedValue Node to Quantity Node
then assign the TimedValue to NRJQuantity
then assign the TimedValue to AvgCal
then assign the TimedValue to AvgDens
This solution is correct, it was also suggested by Mohit Kumar Gupta and marked an corrected answer in the forum. In fact this is what’s normally we found in this type of mapping problems however this is not the best option in terms of performance. If we analyze the XSLT regenerated by the BizTalk mapping engine by:
xsl:for-each
select
"TimeSeries"
xsl:variable
name
"var:v1"
"userCSharp:LogicalEq(string(@Path) , "1")"
/>
xsl:if
test
"$var:v1"
"var:v2"
"string(@Path)"
"var:v3"
"userCSharp:LogicalEq($var:v2 , "1")"
"string($var:v3)='true'"
"var:v4"
"TimedValues/TimedValue/text()"
ns0:Quantity
xsl:value-of
"$var:v4"
"var:v5"
"var:v6"
"userCSharp:LogicalEq($var:v5 , "2")"
"$var:v6"
"string($var:v6)='true'"
"var:v7"
ns0:NRJQuantity
"$var:v7"
> ...
This means that if we have 50 occurrences of “TimeSeries” node, we will have 50 iterations for each element that we want to map in the destination schema… so this approach may be easy to implement and somewhat acceptable in small messages is extremely disadvantageous for large message.
"string(@Path) = '1' "
"string(@Path) = '2' "
"string(@Path) = '3' "
"string(@Path) = '4' "
xsl:choose
xsl:when
test="count(//TimeSeries[@
'1'
]) > 0">
"//TimeSeries[@Path='1']/TimedValues/TimedValue/text()"
'2'
"//TimeSeries[@Path='2']/TimedValues/TimedValue/text()"
'3'
"//TimeSeries[@Path='3']/TimedValues/TimedValue/text()"
'4'
"//TimeSeries[@Path='4']/TimedValues/TimedValue/text()"
Original source by Sandro Pereira: BizTalk Mapper Patterns: How to map values from a repeating node into a single node using conditions
Read suggested related topics: