jQuery in Action, 2nd edition*
The moose likes XML and Related Technologies and the fly likes for-each executions required seperately, but not in nested for-each for a complex xslt mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "for-each executions required seperately, but not in nested for-each for a complex xslt mapping" Watch "for-each executions required seperately, but not in nested for-each for a complex xslt mapping" New topic
Author

for-each executions required seperately, but not in nested for-each for a complex xslt mapping

Raj Ms
Greenhorn

Joined: Mar 18, 2014
Posts: 6
I need to do a for loop for the following XSLT:

Problem is with i am able to traverse only one EntryDetailRec and all in AddendaRec if used single for-each. I want to loop for both, but not in a nested for-loop.
Please help.

<ebo:CreateReturnedItemListEBM>
<DataArea>
<xsl:for-each select="/imp1:GENVNDRReturnedItem/imp1:EntryDetailRec">
<xsl:for-each select="/imp1:GENVNDRReturnedItem/imp1:AddendaRec">
<ebo:CreateReturnedItemList>
<ebo:AccountID>
<xsl:value-of select="imp1:IndvlIdfnNumber"/>
</ebo:AccountID>
<ebo:BankDetail>
<ebo:AccountNumber>
<ebo:Old>
<xsl:value-of select="imp1fiAccttNumber"/>
</ebo:Old>
<xsl:if test='concat(../imp1:AddendaRec/imp1:TransactionCode,../imp1:AddendaRec/imp1:TypeOfReturn,../imp1:AddendaRec/imp1:ReturnReasonCode) = "98C01"'>
<!--Start Logic for work: Raj-->
<!--When Change Reason Code =01 or 06-->
<xsl:if test='../imp1:AddendaRec/imp1:ReturnReasonCode = "01" or "06"'>
<ebo:New>
substring(oraext:right-trim(bpws:getVariableData('Receive1_Read_InputVariable_1','body','/ns4:Root-Element/ns4:RECORD1/ns4:C2')),0,16)
</ebo:New>
</xsl:if>
<!--When Change Reason Code =03-->
<xsl:if test='../imp1:AddendaRec/imp1:ReturnReasonCode = "03"'>
<ebo:New>

substring(oraext:right-trim(bpws:getVariableData('Receive1_Read_InputVariable_1','body','/ns4:Root-Element/ns4:RECORD1/ns4:C2')),13,29)
</ebo:New>
</xsl:if>
<!--When Change Reason Code =07-->
<xsl:if test='../imp1:AddendaRec/imp1:ReturnReasonCode = "03"'>
<ebo:New>

substring(oraext:right-trim(bpws:getVariableData('Receive1_Read_InputVariable_1','body','/ns4:Root-Element/ns4:RECORD1/ns4:C2')),10,26)
</ebo:New>
</xsl:if>


</xsl:if>
</ebo:AccountNumber>
<ebo:RoutingNumber>
<ebo:Old>
<xsl:value-of select="../imp1:AddendaRec/imp1:OrginalABA"/>
</ebo:Old>
<xsl:if test='../imp1:AddendaRec/imp1:ReturnReasonCode = "02" or "03" or "07"'>
<ebo:New>
<!--When Change Reason Code =02 or 03 or 07 -->
substring(oraext:right-trim(bpws:getVariableData('Receive1_Read_InputVariable_1','body','/ns4:Root-Element/ns4:RECORD1/ns4:C2')),0,8)
</ebo:New>
</xsl:if>

</ebo:RoutingNumber>
</ebo:BankDetail>
<ebo:Payment>
<ebo:Amount>
<xsl:value-of select="imp1ollarAmount"/>
</ebo:Amount>
<eboate>
<xsl:value-of select="../imp1:BatchHdrRec/imp1:CmpnyDescDate"/>
</eboate>
</ebo:Payment>
<ebo:ReturnDetail>
<ebo:Type>
<xsl:value-of select="../imp1:AddendaRec/imp1:TypeOfReturn"/>
</ebo:Type>
<ebo:Reason>

<!--ReturnReason COde-->
<xsl:value-of select="../imp1:AddendaRec/imp1:ReturnReasonCode"/>
</ebo:Reason>
<eboispositionCode>
<xsl:value-of select="../imp1:AddendaRec/imp1:TypeOfReturn"/>
</eboispositionCode>
</ebo:ReturnDetail>
</ebo:CreateReturnedItemList>
</xsl:for-each>
</xsl:for-each>
</DataArea>
</ebo:CreateReturnedItemListEBM>
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 537
    
    3
Problem is with i am able to traverse only one EntryDetailRec and all in AddendaRec if used single for-each.

Why it traverses only one EntryDetailRec, if there are more, is obviously implausible. It is probably stopped already by error encountered before even the second EntryDetailRec is to be worked on.

I want to loop for both, but not in a nested for-loop.

It is not whether you want nested for-loop or not. It is whether it is correct to write nested for-loop or not.

<xsl:for-each select="/imp1:GENVNDRReturnedItem/imp1:EntryDetailRec">
<xsl:for-each select="/imp1:GENVNDRReturnedItem/imp1:AddendaRec">
<!-- etc etc -->
</xsl:for-each>
</xsl:for-each>

That is a "cartesian product" thing, mainly the context for the for-each starts from the root /. It is not a matter of want it or not. It is a matter of rightly or wrongly doing the task. But I think since the working within the loop seems at least superficially not coupling between the two elements selected, I don't think you really mean to have a cartesian product over them.

The other end of the spectrum would be this, if you want to select either of them encountered along the way...

It may fit what you need or it may not : no way to know.

Within the xsl:for-each, if you perform different work according to whether the context being imp1:EntryDetailRec or imp1:AddendaRec, you can use a conditional with test like this (to simplify the matter)


In any case, I see the rest of the template contains quite a few obvious errors such as this, as a typical example, cannot be right:
<xsl:if test='../imp1:AddendaRec/imp1:ReturnReasonCode = "01" or "06"'>

Besides the ../imp1:AddendaRec construction is problematic --- it will go back to the first encounter of imp1:AddendaRec to make the test (most probably not what you want???), the "or" keywork is not used like this. A possible rewrite that might inspire you to do the right thing is this.


Another kind of probable errors appearing more than once is
<ebo:New>
substring(oraext:right-trim(bpws:getVariableData('Receive1_Read_InputVariable_1','body','/ns4:Root-Element/ns4:RECORD1/ns4:C2')),0,16)
</ebo:New>

What you meant is probably (?) this.

or something like that...

In any case, that is the different aspects you might work alone with correcting the template in question.
Raj Ms
Greenhorn

Joined: Mar 18, 2014
Posts: 6
I have tested with sample payload and tried to use /imp1:GENVNDRReturnedItem/imp1:EntryDetailRec|/imp1:GENVNDRReturnedItem/imp1:AddendaRec . In payload first set am getting with both EntryDeatilRec and AddendaRec. Second set is EntryDeatilRec is null values and AddendaRec values are same as first set values.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 537
    
    3
With that cryptic report, I take it meaning it is not helpful. I can bear with it, good luck.
 
jQuery in Action, 2nd edition
 
subject: for-each executions required seperately, but not in nested for-each for a complex xslt mapping