This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 31st, when you will be able to use this site as normal.

    Forum Stats

  • 3,890,805 Users
  • 2,269,649 Discussions
  • 7,916,821 Comments

Discussions

For-each Array Element in XSLT

Lior Asras -Oracle
Lior Asras -Oracle Member Posts: 20 Employee
edited May 19, 2021 11:10AM in BPEL

Hi,

I am using SOA 12C

In XSLT I have a for-each

Source side I have a variable which is an header identifier(v_identifier) variable of Invoice

and line identifier(v_lineNumber).



So the requirement is.. for each invoice header, to collect the its lines.


I mean from DB if we get the below data for invoice 1:

<code>

asd

<code>



I tried an get the following:



Source:


<?xml version="1.0" encoding="UTF-8" ?>

<OutputParameters xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/sp/FBDI">

  <P_IN>

     <P_IN_ITEM>

        <INVOICEHEADERIDENTIFIER>1</INVOICEHEADERIDENTIFIER>

        <INVOICELINEIDENTIFIER>1</INVOICELINEIDENTIFIER>

        <INVOICENUMBER>1</INVOICENUMBER>

        <LINENUMBER>69</LINENUMBER>

        <LINETYPE>string69</LINETYPE>

        <QUANTITY>71</QUANTITY>


     </P_IN_ITEM>

     <P_IN_ITEM>

        <INVOICEHEADERIDENTIFIER>1</INVOICEHEADERIDENTIFIER>

        <INVOICELINEIDENTIFIER>1</INVOICELINEIDENTIFIER>

        <LINENUMBER>68</LINENUMBER>

        <LINETYPE>string155</LINETYPE>

        <QUANTITY>157</QUANTITY>

     </P_IN_ITEM>


     <P_IN_ITEM>

        <INVOICEHEADERIDENTIFIER>2</INVOICEHEADERIDENTIFIER>

        <INVOICELINEIDENTIFIER>2</INVOICELINEIDENTIFIER>

        <LINENUMBER>99999999</LINENUMBER>

        <LINETYPE>string241</LINETYPE>

        <QUANTITY>243</QUANTITY>

        <UNITPRICE>244</UNITPRICE>

     </P_IN_ITEM>

  </P_IN>

  <X_RETURN_STATUS>X_RETURN_STATUS259</X_RETURN_STATUS>

  <X_MSG_COUNT>260</X_MSG_COUNT>

  <X_MSG_DATA>X_MSG_DATA261</X_MSG_DATA>

</OutputParameters>




XSLT for-each:

<xsl:for-each select="/ns0:OutputParameters/ns0:P_IN/ns0:P_IN_ITEM[not(ns0:INVOICEHEADERIDENTIFIER = 

     preceding-sibling::ns0:P_IN_ITEM/ns0:INVOICEHEADERIDENTIFIER)]">

     

        <xsl:sort select="ns0:INVOICEHEADERIDENTIFIER"/>

        <xsl:variable name="v_identifier"

            select="/ns0:OutputParameters/ns0:P_IN/ns0:P_IN_ITEM/ns0:INVOICEHEADERIDENTIFIER"/>

       

      <tns:P_ITEM>

         

        <tns:InvoiceNumber>

         <xsl:value-of select="ns0:INVOICEHEADERIDENTIFIER"/>

        </tns:InvoiceNumber> 

  

        <xsl:variable name="v_lineNumber" select="/ns0:OutputParameters/ns0:P_IN/ns0:P_IN_ITEM/ns0:LINENUMBER"/>

      

        <xsl:for-each select="/ns0:OutputParameters/ns0:P_IN/ns0:P_IN_ITEM[ns0:INVOICELINEIDENTIFIER = $v_identifier]

        [not(ns0:LINENUMBER = preceding-sibling::ns0:P_IN_ITEM[ns0:INVOICELINEIDENTIFIER =

        $v_identifier]/ns0:LINENUMBER )]">

         <xsl:if test="ns0:INVOICEHEADERIDENTIFIER = 1 and ns0:LINENUMBER = 68">

           <xsl:choose>

            <xsl:when test="ns0:INVOICEHEADERIDENTIFIER = $v_identifier">

              <tns:invoiceLines>

               <tns:LineNumber>

                 <xsl:value-of select="ns0:LINENUMBER"/>

               </tns:LineNumber>

               <tns:LineType/>

               

              </tns:invoiceLines>

            </xsl:when>

           </xsl:choose>

         </xsl:if>

        </xsl:for-each>

      </tns:P_ITEM>

     </xsl:for-each>


Target:

<tns:P_ITEM>

     <tns:InvoiceNumber>2</tns:InvoiceNumber>

     <tns:invoiceLines>

        <tns:LineNumber>68</tns:LineNumber>

        <tns:LineType/>

        <tns:LineAmount>153</tns:LineAmount>

        <tns:Description>string143</tns:Description>

        <tns:DistributionCombination>string145</tns:DistributionCombination>

     </tns:invoiceLines>

<tns:invoiceLines>

        <tns:LineNumber>69</tns:LineNumber>

        <tns:LineType/>

        <tns:LineAmount>67</tns:LineAmount>

        <tns:Description>string69</tns:Description>

     </tns:invoiceLines>


<tns:invoiceLines>

        <tns:LineNumber>99999999</tns:LineNumber>

        <tns:LineType/>string241

        <tns:LineAmount>243</tns:LineAmount>

        <tns:Description>244</tns:Description>

     </tns:invoiceLines>

  </tns:P_ITEM>

</tns:Root-Element>






I want to get for each header its lines.

<tns:P_ITEM>

     <tns:InvoiceNumber>2</tns:InvoiceNumber>

     <tns:invoiceLines>

        <tns:LineNumber>68</tns:LineNumber>

        <tns:LineType/>

        <tns:LineAmount>153</tns:LineAmount>

        <tns:Description>string143</tns:Description>

        <tns:DistributionCombination>string145</tns:DistributionCombination>

     </tns:invoiceLines>

<tns:invoiceLines>

        <tns:LineNumber>69</tns:LineNumber>

        <tns:LineType/>

        <tns:LineAmount>67</tns:LineAmount>

        <tns:Description>string69</tns:Description>

     </tns:invoiceLines>

  </tns:P_ITEM>

</tns:Root-Element>



How can we achieve this in XSLT?


Many thanks.

Tagged: