Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

For-each Array Element in XSLT

Lior Asras -OracleMay 19 2021 — edited May 19 2021

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.

Comments
Post Details
Added on May 19 2021
0 comments
1,597 views