2016-09-26 84 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,并且没有任何错误,工作正常。 –

相关问题