首页 > 解决方案 > 如何在 BPEL 流程中的 XSLT 转换中为每个和创建数组

问题描述

*****更新*****

如何迭代并收集成行数组?

XML 源和目标:

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>
      <INVOICELINECOUNT>3</INVOICELINECOUNT>
      <ACCOUNTINGDATE>string4</ACCOUNTINGDATE>
      <BUSINESSUNIT>string6</BUSINESSUNIT>
      <ACCOUNTCODINGSTATUS>string8</ACCOUNTCODINGSTATUS>
      <ACCOUNTINGSTATUS>string10</ACCOUNTINGSTATUS>
      <APPROVALSTATUS>string12</APPROVALSTATUS>
      <CONVERSIONDATE>string14</CONVERSIONDATE>
      <CONVERSIONRATE>16</CONVERSIONRATE>
      <CONVERSIONRATETYPE>string17</CONVERSIONRATETYPE>
      <DESCRIPTIONHEADER>string19</DESCRIPTIONHEADER>
      <INVOICEAMOUNT>200</INVOICEAMOUNT>
      <INVOICECURRENCY>string22</INVOICECURRENCY>
      <INVOICEDATE>string24</INVOICEDATE>
      <INVOICEDFFHEADER>string26</INVOICEDFFHEADER>
      <INVOICENUMBER>1</INVOICENUMBER>
      <INVOICESOURCE>string30</INVOICESOURCE>
      <INVOICETYPE>string32</INVOICETYPE>
      <PAYMENTCURRENCY>string34</PAYMENTCURRENCY>
      <PAYMENTTERMS>string36</PAYMENTTERMS>
      <TERMSDATE>string38</TERMSDATE>
      <REQUESTER>string40</REQUESTER>
      <SUPPLIERNUMBER>string42</SUPPLIERNUMBER>
      <SUPPLIERSITE>string44</SUPPLIERSITE>
      <TAXATIONCOUNTRY>string46</TAXATIONCOUNTRY>
      <CREATEDBY>string48</CREATEDBY>
      <CREATIONDATE>string50</CREATIONDATE>
      <DOCUMENTCATEGORY>string52</DOCUMENTCATEGORY>
      <VALIDATIONSTATUS>string54</VALIDATIONSTATUS>
      <BASEAMOUNT>56</BASEAMOUNT>
      <BUDGETDATE>2021-05-16T15:31:30.999</BUDGETDATE>
      <DESCRIPTIONLINE>string57</DESCRIPTIONLINE>
      <DISTRIBUTIONCOMBINATION>string59</DISTRIBUTIONCOMBINATION>
      <INVOICELINEDFF>string61</INVOICELINEDFF>
      <ITEM>string63</ITEM>
      <ITEMDESCRIPTION>string65</ITEMDESCRIPTION>
      <LINEAMOUNT>67</LINEAMOUNT>
      <LINENUMBER>69</LINENUMBER>
      <LINETYPE>string69</LINETYPE>
      <QUANTITY>71</QUANTITY>
      <UNITPRICE>72</UNITPRICE>
      <UOM>string73</UOM>
      <MATCHBASIS>string75</MATCHBASIS>
      <MATCHOPTION>string77</MATCHOPTION>
      <MATCHTYPE>string79</MATCHTYPE>
      <PURCHASEORDERLINENUMBER>81</PURCHASEORDERLINENUMBER>
      <PURCHASEORDERNUMBER>string82</PURCHASEORDERNUMBER>
      <PURCHASEORDERSCHEDLINENUMBER>84</PURCHASEORDERSCHEDLINENUMBER>
      <TAXCLASSIFICATION>string85</TAXCLASSIFICATION>
   </P_IN_ITEM>
   <P_IN_ITEM>
      <INVOICEHEADERIDENTIFIER>1</INVOICEHEADERIDENTIFIER>
      <INVOICELINEIDENTIFIER>1</INVOICELINEIDENTIFIER>
      <INVOICELINECOUNT>89</INVOICELINECOUNT>
      <ACCOUNTINGDATE>string90</ACCOUNTINGDATE>
      <BUSINESSUNIT>string6</BUSINESSUNIT>
      <ACCOUNTCODINGSTATUS>string94</ACCOUNTCODINGSTATUS>
      <ACCOUNTINGSTATUS>string96</ACCOUNTINGSTATUS>
      <APPROVALSTATUS>string98</APPROVALSTATUS>
      <CONVERSIONDATE>string100</CONVERSIONDATE>
      <CONVERSIONRATE>102</CONVERSIONRATE>
      <CONVERSIONRATETYPE>string103</CONVERSIONRATETYPE>
      <DESCRIPTIONHEADER>string105</DESCRIPTIONHEADER>
      <INVOICEAMOUNT>200</INVOICEAMOUNT>
      <INVOICECURRENCY>string108</INVOICECURRENCY>
      <INVOICEDATE>string110</INVOICEDATE>
      <INVOICEDFFHEADER>string112</INVOICEDFFHEADER>
      <INVOICENUMBER>1</INVOICENUMBER>
      <INVOICESOURCE>string116</INVOICESOURCE>
      <INVOICETYPE>string118</INVOICETYPE>
      <PAYMENTCURRENCY>string120</PAYMENTCURRENCY>
      <PAYMENTTERMS>string122</PAYMENTTERMS>
      <TERMSDATE>string124</TERMSDATE>
      <REQUESTER>string126</REQUESTER>
      <SUPPLIERNUMBER>string128</SUPPLIERNUMBER>
      <SUPPLIERSITE>string130</SUPPLIERSITE>
      <TAXATIONCOUNTRY>string132</TAXATIONCOUNTRY>
      <CREATEDBY>string134</CREATEDBY>
      <CREATIONDATE>string136</CREATIONDATE>
      <DOCUMENTCATEGORY>string138</DOCUMENTCATEGORY>
      <VALIDATIONSTATUS>string140</VALIDATIONSTATUS>
      <BASEAMOUNT>142</BASEAMOUNT>
      <BUDGETDATE>2021-05-16T15:31:31.000</BUDGETDATE>
      <DESCRIPTIONLINE>string143</DESCRIPTIONLINE>
      <DISTRIBUTIONCOMBINATION>string145</DISTRIBUTIONCOMBINATION>
      <INVOICELINEDFF>string147</INVOICELINEDFF>
      <ITEM>string149</ITEM>
      <ITEMDESCRIPTION>string151</ITEMDESCRIPTION>
      <LINEAMOUNT>153</LINEAMOUNT>
      <LINENUMBER>68</LINENUMBER>
      <LINETYPE>string155</LINETYPE>
      <QUANTITY>157</QUANTITY>
      <UNITPRICE>158</UNITPRICE>
      <UOM>string159</UOM>
      <MATCHBASIS>string161</MATCHBASIS>
      <MATCHOPTION>string163</MATCHOPTION>
      <MATCHTYPE>string165</MATCHTYPE>
      <PURCHASEORDERLINENUMBER>167</PURCHASEORDERLINENUMBER>
      <PURCHASEORDERNUMBER>string168</PURCHASEORDERNUMBER>
      <PURCHASEORDERSCHEDLINENUMBER>170</PURCHASEORDERSCHEDLINENUMBER>
      <TAXCLASSIFICATION>string171</TAXCLASSIFICATION>
   </P_IN_ITEM>
   <P_IN_ITEM>
      <INVOICEHEADERIDENTIFIER>2</INVOICEHEADERIDENTIFIER>
      <INVOICELINEIDENTIFIER>2</INVOICELINEIDENTIFIER>
      <INVOICELINECOUNT>175</INVOICELINECOUNT>
      <ACCOUNTINGDATE>string176</ACCOUNTINGDATE>
      <BUSINESSUNIT>string178</BUSINESSUNIT>
      <ACCOUNTCODINGSTATUS>string180</ACCOUNTCODINGSTATUS>
      <ACCOUNTINGSTATUS>string182</ACCOUNTINGSTATUS>
      <APPROVALSTATUS>string184</APPROVALSTATUS>
      <CONVERSIONDATE>string186</CONVERSIONDATE>
      <CONVERSIONRATE>188</CONVERSIONRATE>
      <CONVERSIONRATETYPE>string189</CONVERSIONRATETYPE>
      <DESCRIPTIONHEADER>string191</DESCRIPTIONHEADER>
      <INVOICEAMOUNT>3</INVOICEAMOUNT>
      <INVOICECURRENCY>string194</INVOICECURRENCY>
      <INVOICEDATE>string196</INVOICEDATE>
      <INVOICEDFFHEADER>string198</INVOICEDFFHEADER>
      <INVOICENUMBER>222222222</INVOICENUMBER>
      <INVOICESOURCE>string202</INVOICESOURCE>
      <INVOICETYPE>string204</INVOICETYPE>
      <PAYMENTCURRENCY>string206</PAYMENTCURRENCY>
      <PAYMENTTERMS>string208</PAYMENTTERMS>
      <TERMSDATE>string210</TERMSDATE>
      <REQUESTER>string212</REQUESTER>
      <SUPPLIERNUMBER>string214</SUPPLIERNUMBER>
      <SUPPLIERSITE>string216</SUPPLIERSITE>
      <TAXATIONCOUNTRY>string218</TAXATIONCOUNTRY>
      <CREATEDBY>string220</CREATEDBY>
      <CREATIONDATE>string222</CREATIONDATE>
      <DOCUMENTCATEGORY>string224</DOCUMENTCATEGORY>
      <VALIDATIONSTATUS>string226</VALIDATIONSTATUS>
      <BASEAMOUNT>228</BASEAMOUNT>
      <BUDGETDATE>2021-05-16T15:31:31.001</BUDGETDATE>
      <DESCRIPTIONLINE>string229</DESCRIPTIONLINE>
      <DISTRIBUTIONCOMBINATION>string231</DISTRIBUTIONCOMBINATION>
      <INVOICELINEDFF>string233</INVOICELINEDFF>
      <ITEM>string235</ITEM>
      <ITEMDESCRIPTION>string237</ITEMDESCRIPTION>
      <LINEAMOUNT>239</LINEAMOUNT>
      <LINENUMBER>99999999</LINENUMBER>
      <LINETYPE>string241</LINETYPE>
      <QUANTITY>243</QUANTITY>
      <UNITPRICE>244</UNITPRICE>
      <UOM>string245</UOM>
      <MATCHBASIS>string247</MATCHBASIS>
      <MATCHOPTION>string249</MATCHOPTION>
      <MATCHTYPE>string251</MATCHTYPE>
      <PURCHASEORDERLINENUMBER>253</PURCHASEORDERLINENUMBER>
      <PURCHASEORDERNUMBER>string254</PURCHASEORDERNUMBER>
      <PURCHASEORDERSCHEDLINENUMBER>256</PURCHASEORDERSCHEDLINENUMBER>
      <TAXCLASSIFICATION>string257</TAXCLASSIFICATION>
   </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>

There is 2 headers:
Header number 1 with 2 lines(68,69)
Header number 2 with 1 line(99999999)

这是从 DB 返回的展平数据,我无法更改。 展平数据库中的数据

和这个

我在 XSLT 中尝试了这个逻辑:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0" xmlns:tns="http://Invoice.com/ServiceName"
                xmlns:mhdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.mediator.service.common.functions.MediatorExtnFunction"
                xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
                xmlns:ns0="http://xmlns.oracle.com/pcbpel/adapter/db/sp/FBDI"
                xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
                xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator"
                xmlns:oracle-xsl-mapper="http://www.oracle.com/xsl/mapper/schemas"
                xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue"
                xmlns:oraxsl="http://www.oracle.com/XSL/Transform/java"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                exclude-result-prefixes=" xsd oracle-xsl-mapper xsi xsl ns0 tns mhdr oraext xp20 xref socket dvm oraxsl"
                xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
                xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                 xmlns:jca="http://xmlns.oracle.com/pcbpel/wsdl/jca/"
                xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype"
                 xmlns:ns2="http://xmlJSON.com/ServiceName">
   <oracle-xsl-mapper:schema>
      <!--SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY.-->
      <oracle-xsl-mapper:mapSources>
         <oracle-xsl-mapper:source type="WSDL">
            <oracle-xsl-mapper:schema location="../WSDLs/FBDI.wsdl"/>
            <oracle-xsl-mapper:rootElement name="OutputParameters"
                                           namespace="http://xmlns.oracle.com/pcbpel/adapter/db/sp/FBDI%22/%3E
         </oracle-xsl-mapper:source>
      </oracle-xsl-mapper:mapSources>
      <oracle-xsl-mapper:mapTargets>
         <oracle-xsl-mapper:target type="WSDL">
            <oracle-xsl-mapper:schema location="../WSDLs/.wsdl"/>
            <oracle-xsl-mapper:rootElement name="Root-Element" namespace="http://Invoice.com/ServiceName"/>
         </oracle-xsl-mapper:target>
      </oracle-xsl-mapper:mapTargets>
      <!--GENERATED BY ORACLE XSL MAPPER 12.2.1.3.0(XSLT Build 170820.1700.2557) AT [SUN MAY 16 17:24:58 IDT 2021].-->
   </oracle-xsl-mapper:schema>
   <!--User Editing allowed BELOW this line - DO NOT DELETE THIS LINE-->
   <xsl:template match="/">
      <tns:Root-Element>
        
         <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" case-order="lower-first"/>
               <xsl:variable name="v_identifier"
                       select="/ns0:OutputParameters/ns0:P_IN/ns0:P_IN_ITEM/ns0:INVOICEHEADERIDENTIFIER"/>
            
            <tns:P_ITEM>
               <tns:AccountingDate/>
               <tns:BusinessUnit>
                  <xsl:value-of select="ns0:BUSINESSUNIT"/>
               </tns:BusinessUnit>
               <tns:ProcurementBU/>
               <tns:InvoiceNumber>
                  <xsl:value-of select="ns0:INVOICEHEADERIDENTIFIER"/>
               </tns:InvoiceNumber>
               <tns:InvoiceCurrency/>
               <tns:InvoiceAmount>
                  <xsl:value-of select="ns0:INVOICEAMOUNT"/>
               </tns:InvoiceAmount>
               <tns:InvoiceDate>
                  <xsl:value-of select="ns0:INVOICEDATE"/>
               </tns:InvoiceDate>
               <tns:Supplier>
                  <xsl:value-of select="ns0:SUPPLIERNUMBER"/>
               </tns:Supplier>
               <tns:SupplierSite>
                  <xsl:value-of select="ns0:SUPPLIERSITE"/>
               </tns:SupplierSite>
               <tns:PaymentCurrency>
                  <xsl:value-of select="ns0:PAYMENTCURRENCY"/>
               </tns:PaymentCurrency>
               <tns:InvoiceType>
                  <xsl:value-of select="ns0:INVOICETYPE"/>
               </tns:InvoiceType>
               <tns:Description>
                  <xsl:value-of select="ns0:DESCRIPTIONHEADER"/>
               </tns:Description>
               <tns:TermsDate>
                  <xsl:value-of select="ns0:TERMSDATE"/>
               </tns:TermsDate>
               <tns:Requester>
                  <xsl:value-of select="ns0:REQUESTER"/>
               </tns:Requester>
                <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][ns0:LINENUMBER = $v_lineNumber]">
                
                           <tns:invoiceLines>
                              <tns:LineNumber>
                                 <xsl:value-of select="ns0:LINENUMBER"/>
                              </tns:LineNumber>
                              <tns:LineType/>
                              <tns:LineAmount>
                                 <xsl:value-of select="ns0:LINEAMOUNT"/>
                              </tns:LineAmount>
                              <tns:Description>
                                 <xsl:value-of select="ns0:DESCRIPTIONLINE"/>
                              </tns:Description>
                              <tns:DistributionCombination>
                                 <xsl:value-of select="ns0:DISTRIBUTIONCOMBINATION"/>
                              </tns:DistributionCombination>
                           </tns:invoiceLines>
                         
               </xsl:for-each>
            </tns:P_ITEM>
         </xsl:for-each>
      </tns:Root-Element>
   </xsl:template>
</xsl:stylesheet>





然后返回输出:


Target

<?xml version = '1.0' encoding = 'UTF-8'?>
<tns:Root-Element xmlns:jca="http://xmlns.oracle.com/pcbpel/wsdl/jca/" xmlns:ns2="http://xmlJSON.com/ServiceName" xmlns:ns1="http://xmlns.oracle.com/pcbpel/adapter/db/ad/FBDI" xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:client="http://xmlns.oracle.com/adPELProcess" xmlns:tns="http://Invoice.com/ServiceName">
   <tns:P_ITEM>
      <tns:AccountingDate/>
      <tns:BusinessUnit>string6</tns:BusinessUnit>
      <tns:ProcurementBU/>
      <tns:InvoiceNumber>1</tns:InvoiceNumber>
      <tns:InvoiceCurrency/>
      <tns:InvoiceAmount>200</tns:InvoiceAmount>
      <tns:InvoiceDate>string24</tns:InvoiceDate>
      <tns:Supplier>string42</tns:Supplier>
      <tns:SupplierSite>string44</tns:SupplierSite>
      <tns:PaymentCurrency>string34</tns:PaymentCurrency>
      <tns:InvoiceType>string32</tns:InvoiceType>
      <tns:Description>string19</tns:Description>
      <tns:TermsDate>string38</tns:TermsDate>
      <tns:Requester>string40</tns:Requester>
      <tns:invoiceLines>
         <tns:LineNumber>1</tns:LineNumber>
         <tns:LineType/>
         <tns:LineAmount>67</tns:LineAmount>
         <tns:Description>string57</tns:Description>
         <tns:DistributionCombination>string59</tns:DistributionCombination>
      </tns:invoiceLines>
      <tns:invoiceLines>
         <tns:LineNumber>2</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>99999999</tns:LineNumber>
         <tns:LineType/>
         <tns:LineAmount>239</tns:LineAmount>
         <tns:Description>string229</tns:Description>
         <tns:DistributionCombination>string231</tns:DistributionCombination>
      </tns:invoiceLines>
   </tns:P_ITEM>
   <tns:P_ITEM>
      <tns:AccountingDate/>
      <tns:BusinessUnit>string178</tns:BusinessUnit>
      <tns:ProcurementBU/>
      <tns:InvoiceNumber>2</tns:InvoiceNumber>
      <tns:InvoiceCurrency/>
      <tns:InvoiceAmount>3</tns:InvoiceAmount>
      <tns:InvoiceDate>string196</tns:InvoiceDate>
      <tns:Supplier>string214</tns:Supplier>
      <tns:SupplierSite>string216</tns:SupplierSite>
      <tns:PaymentCurrency>string206</tns:PaymentCurrency>
      <tns:InvoiceType>string204</tns:InvoiceType>
      <tns:Description>string191</tns:Description>
      <tns:TermsDate>string210</tns:TermsDate>
      <tns:Requester>string212</tns:Requester>
      <tns:invoiceLines>
         <tns:LineNumber>1</tns:LineNumber>
         <tns:LineType/>
         <tns:LineAmount>67</tns:LineAmount>
         <tns:Description>string57</tns:Description>
         <tns:DistributionCombination>string59</tns:DistributionCombination>
      </tns:invoiceLines>
      <tns:invoiceLines>
         <tns:LineNumber>2</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>99999999</tns:LineNumber>
         <tns:LineType/>
         <tns:LineAmount>239</tns:LineAmount>
         <tns:Description>string229</tns:Description>
         <tns:DistributionCombination>string231</tns:DistributionCombination>
      </tns:invoiceLines>
   </tns:P_ITEM>
</tns:Root-Element>



我想要所需的输出:

 

<?xml version = '1.0' encoding = 'UTF-8'?>
<tns:Root-Element xmlns:jca="http://xmlns.oracle.com/pcbpel/wsdl/jca/" xmlns:ns2="http://xmlJSON.com/ServiceName" xmlns:ns1="http://xmlns.oracle.com/pcbpel/adapter/db/ad/FBDI" xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:client="http://xmlns.oracle.com/adPELProcess" xmlns:tns="http://Invoice.com/ServiceName">
   <tns:P_ITEM>
      <tns:AccountingDate/>
      <tns:BusinessUnit>string6</tns:BusinessUnit>
      <tns:ProcurementBU/>
      <tns:InvoiceNumber>1</tns:InvoiceNumber>
      <tns:InvoiceCurrency/>
      <tns:InvoiceAmount>200</tns:InvoiceAmount>
      <tns:InvoiceDate>string24</tns:InvoiceDate>
      <tns:Supplier>string42</tns:Supplier>
      <tns:SupplierSite>string44</tns:SupplierSite>
      <tns:PaymentCurrency>string34</tns:PaymentCurrency>
      <tns:InvoiceType>string32</tns:InvoiceType>
      <tns:Description>string19</tns:Description>
      <tns:TermsDate>string38</tns:TermsDate>
      <tns:Requester>string40</tns:Requester>
      <tns:invoiceLines>
         <tns:LineNumber>1</tns:LineNumber>
         <tns:LineType/>
         <tns:LineAmount>67</tns:LineAmount>
         <tns:Description>string57</tns:Description>
         <tns:DistributionCombination>string59</tns:DistributionCombination>
      </tns:invoiceLines>
      <tns:invoiceLines>
         <tns:LineNumber>2</tns:LineNumber>
         <tns:LineType/>
         <tns:LineAmount>153</tns:LineAmount>
         <tns:Description>string143</tns:Description>
         <tns:DistributionCombination>string145</tns:DistributionCombination>
      </tns:invoiceLines>
    
   </tns:P_ITEM>
   <tns:P_ITEM>
      <tns:AccountingDate/>
      <tns:BusinessUnit>string178</tns:BusinessUnit>
      <tns:ProcurementBU/>
      <tns:InvoiceNumber>2</tns:InvoiceNumber>
      <tns:InvoiceCurrency/>
      <tns:InvoiceAmount>3</tns:InvoiceAmount>
      <tns:InvoiceDate>string196</tns:InvoiceDate>
      <tns:Supplier>string214</tns:Supplier>
      <tns:SupplierSite>string216</tns:SupplierSite>
      <tns:PaymentCurrency>string206</tns:PaymentCurrency>
      <tns:InvoiceType>string204</tns:InvoiceType>
      <tns:Description>string191</tns:Description>
      <tns:TermsDate>string210</tns:TermsDate>
      <tns:Requester>string212</tns:Requester>
       
      <tns:invoiceLines>
         <tns:LineNumber>99999999</tns:LineNumber>
         <tns:LineType/>
         <tns:LineAmount>239</tns:LineAmount>
         <tns:Description>string229</tns:Description>
         <tns:DistributionCombination>string231</tns:DistributionCombination>
      </tns:invoiceLines>
   </tns:P_ITEM>
</tns:Root-Element>



我正在使用 JDeveloper BPEL Designer 将 XSLT 文件放在哪里?XSLT 是否保存为 .xsl 文件,然后将其导入项目文件夹?分配的外观如何?我想将新列表分配给 datacontainerreferencelist 类型的变量(用 XSD 定义,它具有给定的结构如何在 XSLT 中为每个执行它,可能吗?

谢谢。

标签: xmlxsltxslt-2.0jdeveloperbpel

解决方案


请尝试以下 XSLT。

您需要为tns前缀指定真实的命名空间 URI。

XSLT

<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tns="uri">
    <xsl:output indent="yes" method="xml" encoding="utf-8"/>

    <xsl:template match="/P_IN">
        <tns:P_IN>
            <xsl:for-each-group select="P_IN_ITEM" group-by="INVOICEHEADERIDENTIFIER">
                <xsl:sort select="current-grouping-key()"/>
                <tns:P_ITEM>
                    <tns:InvoiceNumber>
                        <xsl:value-of select="current-grouping-key()"/>
                    </tns:InvoiceNumber>
                    <xsl:for-each select="current-group()">
                        <xsl:sort select="LINENUMBER"/>
                        <tns:invoiceLines>
                            <tns:LineNumber>
                                <xsl:value-of select="LINENUMBER"/>
                            </tns:LineNumber>
                            <tns:LineType>
                                <xsl:value-of select="LINETYPE"/>
                            </tns:LineType>
                            <tns:Quantity>
                                <xsl:value-of select="QUANTITY"/>
                            </tns:Quantity>
                        </tns:invoiceLines>
                    </xsl:for-each>
                </tns:P_ITEM>
            </xsl:for-each-group>
        </tns:P_IN>
    </xsl:template>
</xsl:stylesheet>

输出

<?xml version='1.0' encoding='utf-8' ?>
<tns:P_IN xmlns:tns="uri">
  <tns:P_ITEM>
    <tns:InvoiceNumber>1</tns:InvoiceNumber>
    <tns:invoiceLines>
      <tns:LineNumber>1</tns:LineNumber>
      <tns:LineType>string155</tns:LineType>
      <tns:Quantity>157</tns:Quantity>
    </tns:invoiceLines>
    <tns:invoiceLines>
      <tns:LineNumber>2</tns:LineNumber>
      <tns:LineType>string69</tns:LineType>
      <tns:Quantity>71</tns:Quantity>
    </tns:invoiceLines>
  </tns:P_ITEM>
  <tns:P_ITEM>
    <tns:InvoiceNumber>2</tns:InvoiceNumber>
    <tns:invoiceLines>
      <tns:LineNumber>123</tns:LineNumber>
      <tns:LineType>string543</tns:LineType>
      <tns:Quantity>879</tns:Quantity>
    </tns:invoiceLines>
    <tns:invoiceLines>
      <tns:LineNumber>99999999</tns:LineNumber>
      <tns:LineType>string241</tns:LineType>
      <tns:Quantity>243</tns:Quantity>
    </tns:invoiceLines>
  </tns:P_ITEM>
</tns:P_IN>

XSLT #2

<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xpath-default-namespace="http://xmlns.oracle.com/pcbpel/adapter/db/sp/FBDI">
    <xsl:output indent="yes" method="xml" encoding="utf-8"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="P_IN">
        <tns:Root-Element xmlns:jca="http://xmlns.oracle.com/pcbpel/wsdl/jca/" xmlns:ns2="http://xmlJSON.com/ServiceName" xmlns:ns1="http://xmlns.oracle.com/pcbpel/adapter/db/ad/FBDI" xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype"
                          xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:client="http://xmlns.oracle.com/adPELProcess" xmlns:tns="http://Invoice.com/ServiceName">
            <xsl:for-each-group select="P_IN_ITEM" group-by="INVOICEHEADERIDENTIFIER">
                <xsl:sort select="current-grouping-key()"/>
                <tns:P_ITEM>
                    <tns:AccountingDate/>
                    <tns:BusinessUnit>
                        <xsl:value-of select="BUSINESSUNIT"/>
                    </tns:BusinessUnit>
                    <tns:ProcurementBU/>
                    <tns:InvoiceNumber>
                        <xsl:value-of select="current-grouping-key()"/>
                    </tns:InvoiceNumber>
                    <tns:InvoiceCurrency/>
                    <tns:InvoiceAmount>
                        <xsl:value-of select="INVOICEAMOUNT"/>
                    </tns:InvoiceAmount>
                    <tns:InvoiceDate>
                        <xsl:value-of select="INVOICEDATE"/>
                    </tns:InvoiceDate>
                    <tns:Supplier>
                        <xsl:value-of select="SUPPLIERNUMBER"/>
                    </tns:Supplier>
                    <!--Add here the rest of the elements-->
                    <xsl:for-each select="current-group()">
                        <xsl:sort select="LINENUMBER"/>
                        <tns:invoiceLines>
                            <tns:LineNumber>
                                <xsl:value-of select="LINENUMBER"/>
                            </tns:LineNumber>
                            <tns:LineType>
                                <xsl:value-of select="LINETYPE"/>
                            </tns:LineType>
                            <tns:LineAmount>
                                <xsl:value-of select="LINEAMOUNT"/>
                            </tns:LineAmount>
                            <tns:Description>
                                <xsl:value-of select="DESCRIPTIONLINE"/>
                            </tns:Description>
                            <tns:DistributionCombination>
                                <xsl:value-of select="DISTRIBUTIONCOMBINATION"/>
                            </tns:DistributionCombination>
                        </tns:invoiceLines>
                    </xsl:for-each>
                </tns:P_ITEM>
            </xsl:for-each-group>
        </tns:Root-Element>
    </xsl:template>

    <xsl:template match="X_RETURN_STATUS | X_MSG_COUNT | X_MSG_DATA"/>
</xsl:stylesheet>

输出 XML #2

<?xml version='1.0' encoding='utf-8' ?>
<tns:Root-Element xmlns:jca="http://xmlns.oracle.com/pcbpel/wsdl/jca/" xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://Invoice.com/ServiceName" xmlns:ns1="http://xmlns.oracle.com/pcbpel/adapter/db/ad/FBDI" xmlns:ns2="http://xmlJSON.com/ServiceName" xmlns:client="http://xmlns.oracle.com/adPELProcess" xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype">
  <tns:P_ITEM>
    <tns:AccountingDate/>
    <tns:BusinessUnit>string6</tns:BusinessUnit>
    <tns:ProcurementBU/>
    <tns:InvoiceNumber>1</tns:InvoiceNumber>
    <tns:InvoiceCurrency/>
    <tns:InvoiceAmount>200</tns:InvoiceAmount>
    <tns:InvoiceDate>string24</tns:InvoiceDate>
    <tns:Supplier>string42</tns:Supplier>
    <tns:invoiceLines>
      <tns:LineNumber>68</tns:LineNumber>
      <tns:LineType>string155</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>string69</tns:LineType>
      <tns:LineAmount>67</tns:LineAmount>
      <tns:Description>string57</tns:Description>
      <tns:DistributionCombination>string59</tns:DistributionCombination>
    </tns:invoiceLines>
  </tns:P_ITEM>
  <tns:P_ITEM>
    <tns:AccountingDate/>
    <tns:BusinessUnit>string178</tns:BusinessUnit>
    <tns:ProcurementBU/>
    <tns:InvoiceNumber>2</tns:InvoiceNumber>
    <tns:InvoiceCurrency/>
    <tns:InvoiceAmount>3</tns:InvoiceAmount>
    <tns:InvoiceDate>string196</tns:InvoiceDate>
    <tns:Supplier>string214</tns:Supplier>
    <tns:invoiceLines>
      <tns:LineNumber>99999999</tns:LineNumber>
      <tns:LineType>string241</tns:LineType>
      <tns:LineAmount>239</tns:LineAmount>
      <tns:Description>string229</tns:Description>
      <tns:DistributionCombination>string231</tns:DistributionCombination>
    </tns:invoiceLines>
  </tns:P_ITEM>
</tns:Root-Element>

推荐阅读