2016-09-26 83 views
0

節點1:導線通過在一個單一的XSLT兩個不同的XML節點的所有子節點

<retrieveSubscriberDetailResponse xmlns:client="http://xmlns.oracle.com/SBLPOAP/POAPRetrieveSubscriberDetail/POAPRetrieveSubscriberDetailProcess" xmlns="http://xmlns.oracle.com/SBLPOAP/POAPRetrieveSubscriberDetail/POAPRetrieveSubscriberDetailProcess"> 
<client:promotions> 
<client:promotion> 
<client:id>139</client:id> 
<client:name>P_499_Wolverine</client:name> 
<client:Description/> 
<client:activationDt>2015-05-10T02:37:16+08:00</client:activationDt>  <client:expiryDt/> 
</client:promotion> 
<client:promotion> 
<client:id>71</client:id> 
<client:name>Free XYZP</client:name> 
<client:Description/> 
<client:activationDt>2016-01-29T15:30:58+08:00</client:activationDt> 
<client:expiryDt>2017-06-01T00:00:00+08:00</client:expiryDt> 
</client:promotion> 
</client:promotions> 
</retrieveSubscriberDetailResponse> 

節點2:

<processResponse xmlns:ns3="http://xmlns.oracle.com/Custom/KPProductsAPI/KPProductsAPI"  xmlns="http://xmlns.oracle.com/Custom/KPProductsAPI/KPProductsAPI"> 
<ns3:promotions> 
<ns3:promotion> 
<ns3:id>139</ns3:id> 
<ns3:name>KP_MHP_499_Wolverine_KP</ns3:name> 
<ns3:activationDt>2015-05-10T02:37:16+08:00</ns3:activationDt> 
</ns3:promotion> 
<ns3:promotion> 
<ns3:id>140</ns3:id> 
<ns3:name>PQR_XYZ_499_Wolverine_KP</ns3:name> 
<ns3:activationDt>2015-05-10T02:37:16+08:00</ns3:activationDt> 
</ns3:promotion> 
</ns3:promotions> 
</processResponse> 

預期輸出:

<output> 
<promotions> 
<promotion> 
<id>139</client:id> 
<name>KP_MHP_499_Wolverine_KP</name> 
<activationDt>2015-05-10T02:37:16+08:00</activationDt> 
</promotion> 
<promotion> 
<id>71</id> 
<name>Free XYZP</name> 
<Description/> 
<activationDt>2016-01-29T15:30:58+08:00</activationDt> 
<expiryDt>2017-06-01T00:00:00+08:00</expiryDt> 
</promotion> 
</promotions> 
</output> 

這兩個節點是輸入到我的xslt。我的輸出xml應該包含「retrieveSubscriberDetailResponse」中的所有促銷,並且如果任何促銷ID與「processresponse」中的促銷ID相匹配,則應選擇「processresponse」中的促銷活動細節。對於上面給定的Node1和Node2(輸入到xslt)。任何人都可以幫助我實現這一目標嗎?

試過,但沒有運氣:(:(

<xsl:stylesheet version="2.0" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/" 
      xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20" 
      xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:ns2="http://www.abs-c.com/LoggingVariables" 
      xmlns:bpm="http://xmlns.oracle.com/bpmn20/extensions" 
      xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" 
      xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
      xmlns:ns3="http://xmlns.oracle.com/Custom/LFProductsAPI/LFProductsAPI" 
      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
      xmlns:ora="http://schemas.oracle.com/xpath/extension" 
      xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator" 
      xmlns:client="http://xmlns.oracle.com/SBLMVNE/MVNERetrieveSubscriberDetail/MVNERetrieveSubscriberDetailProcess" 
      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:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue" 
      xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath" 
      xmlns:ns0="http://docs.oasis-open.org/wsbpel/2.0/plnktype" 
      xmlns:med="http://schemas.oracle.com/mediator/xpath" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath" 
      xmlns:xdk="http://schemas.oracle.com/bpel/extension/xpath/function/xdk" 
      xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns:ns4="http://xmlns.oracle.com/Custom/ParsingTwoNodesSample/BPELProcess1" 
      xmlns:ns1="http://schemas.oracle.com/bpel/extension" 
      xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap" 
      exclude-result-prefixes="xsi xsl ns2 plnk soap ns3 wsdl client ns0 xsd ns1 ns4 bpws xp20 bpel bpm ora socket mhdr oraext dvm hwf med ids xdk xref ldap" > 
<xsl:param name="Invoke2_process_OutputVariable.payload"/> 
<xsl:key name="cust" match="ns3:promotion" use="ns3:id"/> 
<xsl:template match="/"> 
<ns4:processResponse> 
<ns4:subscribers> 
<ns4:Subscriber> 
<ns4:promotions> 
<xsl:for-each select="/client:retrieveSubscriberDetailResponse/client:subscribers/client:Subsc riber/client:promotions/client:promotion/client:id"> 
<!--<xsl:for-each select="$Invoke2_process_OutputVariable.payload/ns3:processResponse/ns3:promotio ns/ns3:promotion/ns3:id">--> 
<xsl:variable name="lf" select="key('cust', .)"/> 
<ns4:promotion> 
<ns4:id> 
<xsl:value-of select="$lf/ns3:id"/> 
</ns4:id> 
<ns4:name> 
<xsl:value-of select="$lf/ns3:name"/> 
</ns4:name> 
</ns4:promotion> 
</xsl:for-each> 
</ns4:promotions> 
</ns4:Subscriber> 
</ns4:subscribers> 
</ns4:processResponse> 
</xsl:template> 
+0

請發佈最少但完整的代碼片段,以便我們重現此問題。顯示沒有命名空間聲明的XSLT是毫無意義的。至於代碼,''可能應該是'' –

+0

謝謝。更新命名空間@Martin Honnen –

+0

請參閱http://xsltransform.net/94AbWAV以獲得部分解決方案。您必須添加缺少的元素,並且如果不匹配,您將必須決定輸出哪些數據,因爲它在樣本數據中以「71」發生。 –

回答

0

代碼

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="2.0" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20" xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://www.abs-c.com/LoggingVariables" xmlns:bpm="http://xmlns.oracle.com/bpmn20/extensions" xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns3="http://xmlns.oracle.com/Custom/KPProductsAPI/KPProductsAPI" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ora="http://schemas.oracle.com/xpath/extension" xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator" xmlns:client="http://xmlns.oracle.com/SBLPOAP/POAPRetrieveSubscriberDetail/POAPRetrieveSubscriberDetailProcess" 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:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue" xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath" xmlns:ns0="http://docs.oasis-open.org/wsbpel/2.0/plnktype" xmlns:med="http://schemas.oracle.com/mediator/xpath" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath" xmlns:xdk="http://schemas.oracle.com/bpel/extension/xpath/function/xdk" xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns4="http://xmlns.oracle.com/Custom/ParsingTwoNodesSample/BPELProcess1" xmlns:ns1="http://schemas.oracle.com/bpel/extension" xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap" exclude-result-prefixes="xsi xsl ns2 plnk soap ns3 wsdl client ns0 xsd ns1 ns4 bpws xp20 bpel bpm ora socket mhdr oraext dvm hwf med ids xdk xref ldap"> 
    <xsl:param name="Invoke2_process_OutputVariable.payload"> 
     <processResponse xmlns:ns3="http://xmlns.oracle.com/Custom/KPProductsAPI/KPProductsAPI" xmlns="http://xmlns.oracle.com/Custom/KPProductsAPI/KPProductsAPI"> 
      <ns3:promotions> 
       <ns3:promotion> 
        <ns3:id>139</ns3:id> 
        <ns3:name>KP_MHP_499_Wolverine_KP</ns3:name> 
        <ns3:activationDt>2015-05-10T02:37:16+08:00</ns3:activationDt> 
       </ns3:promotion> 
       <ns3:promotion> 
        <ns3:id>140</ns3:id> 
        <ns3:name>PQR_XYZ_499_Wolverine_KP</ns3:name> 
        <ns3:activationDt>2015-05-10T02:37:16+08:00</ns3:activationDt> 
       </ns3:promotion> 
      </ns3:promotions> 
     </processResponse> 
    </xsl:param> 
    <xsl:output indent="yes"/> 
    <xsl:key name="cust" match="ns3:promotion" use="ns3:id"/> 
    <xsl:template match="/"> 
     <ns4:processResponse> 
      <ns4:subscribers> 
       <ns4:Subscriber> 
        <ns4:promotions> 
         <xsl:apply-templates select="//client:promotions/client:promotion"/> 
        </ns4:promotions> 
       </ns4:Subscriber> 
      </ns4:subscribers> 
     </ns4:processResponse> 
    </xsl:template> 
    <xsl:template match="client:promotions/client:promotion[key('cust', client:id, $Invoke2_process_OutputVariable.payload)]"> 
     <xsl:variable name="ref" select="key('cust', client:id, $Invoke2_process_OutputVariable.payload)"/> 
     <ns4:promotion> 
      <ns4:id> 
       <xsl:value-of select="$ref/ns3:id"/> 
      </ns4:id> 
      <ns4:name> 
       <xsl:value-of select="$ref/ns3:name"/> 
      </ns4:name> 
     </ns4:promotion> 
    </xsl:template> 
    <xsl:template match="client:promotions/client:promotion[not(key('cust', client:id, $Invoke2_process_OutputVariable.payload))]"> 
     <ns4:promotion> 
      <ns4:id> 
       <xsl:value-of select="client:id"/> 
      </ns4:id> 
      <ns4:name> 
       <xsl:value-of select="client:name"/> 
      </ns4:name> 
     </ns4:promotion> 
    </xsl:template> 
</xsl:stylesheet> 

將輸入

<retrieveSubscriberDetailResponse xmlns:client="http://xmlns.oracle.com/SBLPOAP/POAPRetrieveSubscriberDetail/POAPRetrieveSubscriberDetailProcess" xmlns="http://xmlns.oracle.com/SBLPOAP/POAPRetrieveSubscriberDetail/POAPRetrieveSubscriberDetailProcess"> 
<client:promotions> 
<client:promotion> 
<client:id>139</client:id> 
<client:name>P_499_Wolverine</client:name> 
<client:Description/> 
<client:activationDt>2015-05-10T02:37:16+08:00</client:activationDt>  <client:expiryDt/> 
</client:promotion> 
<client:promotion> 
<client:id>71</client:id> 
<client:name>Free XYZP</client:name> 
<client:Description/> 
<client:activationDt>2016-01-29T15:30:58+08:00</client:activationDt> 
<client:expiryDt>2017-06-01T00:00:00+08:00</client:expiryDt> 
</client:promotion> 
</client:promotions> 
</retrieveSubscriberDetailResponse> 

到輸出

<?xml version="1.0" encoding="UTF-8"?> 
<ns4:processResponse xmlns:ns4="http://xmlns.oracle.com/Custom/ParsingTwoNodesSample/BPELProcess1"> 
    <ns4:subscribers> 
     <ns4:Subscriber> 
     <ns4:promotions> 
      <ns4:promotion> 
       <ns4:id>139</ns4:id> 
       <ns4:name>KP_MHP_499_Wolverine_KP</ns4:name> 
      </ns4:promotion> 
      <ns4:promotion> 
       <ns4:id>71</ns4:id> 
       <ns4:name>Free XYZP</ns4:name> 
      </ns4:promotion> 
     </ns4:promotions> 
     </ns4:Subscriber> 
    </ns4:subscribers> 
</ns4:processResponse> 

適應您自己在輸出中添加所需的其他元素,它僅僅是爲了向您展示如何使用鍵來交叉引用元素並檢查是否有元素。

+0

我正面臨以下錯誤** XML-22000:(錯誤)解析XSL文件時出錯(Expected')'而不是','。)。**。我認爲這是因爲我試圖將3個參數傳遞給關鍵函數。 我將Invoke2_process_OutputVariable.payload(即Node2)作爲參數傳遞給我的xslt。 –

+0

好吧,如果你沒有XSLT 2.0處理器,那麼你不能使用XSLT 2.0,我發佈的代碼是XSLT 2.0。代碼位於http://xsltransform.net/94AbWAV/2,並且沒有任何錯誤,工作正常。 –

相關問題