2016-09-26 5 views
0

ノード1における2つの異なるXMLノードのすべての子ノードを介し:トラバース単一のXSLT

<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> 

これら2つのノードが入力されています私の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> 

出力

<?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> 
に入力

<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> 

を変換しません

あなたが出力に必要な他の要素を追加するのにそれを適応させるのは、要素を相互参照してキーがあるかどうかを確認するためにキーを使用する方法を示すことに過ぎません。

+0

XML-22000:(エラー) '、'の代わりにXSLファイル(期待値)を解析中にエラーが発生しました。私は3つのパラメータをキー関数に渡そうとしているからだと思います。 Invoke2_process_OutputVariable.payload(つまりNode2)をパラメータとしてmy xsltに渡しています。 –

+0

XSLT 2.0プロセッサを搭載していない場合、XSLT 2.0を使用することはできません。また、私が投稿したコードはXSLT 2.0です。コードはhttp://xsltransform.net/94AbWAV/2にあり、エラーを出すことなく正常に動作します。 –