Xslt 无法使用xsl:for-each映射所有xml元素
我一直在尝试映射特定节点下所有出现的子元素。父产品可能有多个子产品,子产品可能有多个子产品。我的示例xml是这样的Xslt 无法使用xsl:for-each映射所有xml元素,xslt,Xslt,我一直在尝试映射特定节点下所有出现的子元素。父产品可能有多个子产品,子产品可能有多个子产品。我的示例xml是这样的 <?xml version="1.0" encoding="UTF-8" ?> <PreAuthAnet InstanceId="InstanceId1" xmlns="http://www.portal.com/schemas/CRMSync"> <AccountObj>AccountObjparent</AccountObj>
<?xml version="1.0" encoding="UTF-8" ?>
<PreAuthAnet InstanceId="InstanceId1" xmlns="http://www.portal.com/schemas/CRMSync">
<AccountObj>AccountObjparent</AccountObj>
<Status>-0</Status>
<ReasonCode>-0</ReasonCode>
<Days>-0</Days>
<PayType>-0</PayType>
<ChildAccount>
<AccountObj>AccountObjchild1</AccountObj>
<Vin>Vin5</Vin>
<ChildProducts>
<ProductObj>ProductObj1</ProductObj>
<Amount>80.73</Amount>
<Tax>60.73</Tax>
</ChildProducts>
<ChildProducts>
<ProductObj>ProductObj2</ProductObj>
<Amount>82.73</Amount>
<Tax>62.73</Tax>
</ChildProducts>
</ChildAccount>
<ChildAccount>
<AccountObj>AccountObjchild2</AccountObj>
<Vin>Vin10</Vin>
<ChildProducts>
<ProductObj>ProductObj3</ProductObj>
<Amount>200.73</Amount>
<Tax>160.73</Tax>
</ChildProducts>
</ChildAccount>
</PreAuthAnet>
会计对象
-0
-0
-0
-0
会计科目1
葡萄酒5
ProductObj1
80.73
60.73
ProductObj2
82.73
62.73
AccountObjchild2
葡萄酒10
ProductObj3
200.73
160.73
我期望的输出xml是:
<?xml version = '1.0' encoding = 'UTF-8'?>
<msg_out:PreAuthAnet xmlns:msg_out="http://www.portal.com/schemas/CRMSync">
<msg_out:ChildAccount>
<msg_out:ChildAccountObj>AccountObjchild1</msg_out:ChildAccountObj>
<msg_out:VIN>Vin5</msg_out:VIN>
<msg_out:ParentAccountObj>AccountObjparent</msg_out:ParentAccountObj>
<msg_out:Status>0</msg_out:Status>
<msg_out:ReasonCode>0</msg_out:ReasonCode>
<msg_out:Days>0</msg_out:Days>
<msg_out:PayType>0</msg_out:PayType>
<msg_out:ChildProducts>
<msg_out:ProductObj>ProductObj1</msg_out:ProductObj>
<msg_out:Amount>80.73</msg_out:Amount>
<msg_out:Tax>60.73</msg_out:Tax>
</msg_out:ChildProducts>
<msg_out:ChildProducts>
<msg_out:ProductObj>ProductObj2</msg_out:ProductObj>
<msg_out:Amount>81.73</msg_out:Amount>
<msg_out:Tax>61.73</msg_out:Tax>
</msg_out:ChildProducts>
</msg_out:ChildAccount>
<msg_out:ChildAccount>
<msg_out:ChildAccountObj>AccountObjchild2</msg_out:ChildAccountObj>
<msg_out:VIN>Vin10</msg_out:VIN>
<msg_out:ParentAccountObj>AccountObjparent</msg_out:ParentAccountObj>
<msg_out:Status>0</msg_out:Status>
<msg_out:ReasonCode>0</msg_out:ReasonCode>
<msg_out:Days>0</msg_out:Days>
<msg_out:PayType>0</msg_out:PayType>
<msg_out:ChildProducts>
<msg_out:ProductObj>ProductObj10</msg_out:ProductObj>
<msg_out:Amount>100</msg_out:Amount>
<msg_out:Tax>73</msg_out:Tax>
</msg_out:ChildProducts>
</msg_out:PreAuthAnet>
会计科目1
葡萄酒5
会计对象
0
0
0
0
ProductObj1
80.73
60.73
ProductObj2
81.73
61.73
AccountObjchild2
葡萄酒10
会计对象
0
0
0
0
产品OBJ10
100
73
我一直在使用下面的xslt,但它并没有在所有子帐户之间循环。非常感谢您的帮助
<?xml version="1.0" encoding="UTF-8" ?>
<?oracle-xsl-mapper
<!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->
<mapSources>
<source type="WSDL">
<schema location="../SyncPreAuthNotification10Days_AQ.wsdl"/>
<rootElement name="PreAuthAnet" namespace="http://www.portal.com/schemas/CRMSync"/>
</source>
</mapSources>
<mapTargets>
<target type="WSDL">
<schema location="../PreAuth10DaysBPELProcess.wsdl"/>
<rootElement name="PreAuthAnet" namespace="http://www.portal.com/schemas/CRMSync"/>
</target>
</mapTargets>
<!-- GENERATED BY ORACLE XSL MAPPER 11.1.1.7.8(build 150622.2350.0222) AT [MON NOV 02 17:52:42 IST 2015]. -->
?>
<xsl:stylesheet version="1.0"
xmlns:aia="http://www.oracle.com/XSL/Transform/java/oracle.apps.aia.core.xpath.AIAFunctions"
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:client="http://xmlns.oracle.com/Application_Test2/SyncPreAuthNotifications10Days/PreAuth10DaysBPELProcess"
xmlns:pc="http://xmlns.oracle.com/pcbpel/"
xmlns:bpm="http://xmlns.oracle.com/bpmn20/extensions"
xmlns:ns2="http://www.siebel.com/xml/MinacsBRMNotificationsIO"
xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
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: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:jca="http://xmlns.oracle.com/pcbpel/wsdl/jca/"
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:tns="http://xmlns.oracle.com/pcbpel/adapter/AQ/Application_Test2/SyncPreAuthNotifications10Days/SyncPreAuthNotification10Days_AQ"
xmlns:msg_out="http://www.portal.com/schemas/CRMSync"
xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap"
exclude-result-prefixes="xsi xsl pc plt wsdl jca xsd tns msg_out client ns2 aia bpws xp20 bpel bpm ora socket mhdr oraext dvm hwf med ids xdk xref ldap">
<xsl:template match="/">
<msg_out:PreAuthAnet>
<msg_out:ChildAccount>
<msg_out:ChildAccountObj>
<xsl:value-of select="/msg_out:PreAuthAnet/msg_out:ChildAccount/msg_out:AccountObj"/>
</msg_out:ChildAccountObj>
<msg_out:VIN>
<xsl:value-of select="/msg_out:PreAuthAnet/msg_out:ChildAccount/msg_out:Vin"/>
</msg_out:VIN>
<msg_out:ParentAccountObj>
<xsl:value-of select="/msg_out:PreAuthAnet/msg_out:AccountObj"/>
</msg_out:ParentAccountObj>
<msg_out:Status>
<xsl:value-of select="/msg_out:PreAuthAnet/msg_out:Status"/>
</msg_out:Status>
<msg_out:ReasonCode>
<xsl:value-of select="/msg_out:PreAuthAnet/msg_out:ReasonCode"/>
</msg_out:ReasonCode>
<msg_out:Days>
<xsl:value-of select="/msg_out:PreAuthAnet/msg_out:Days"/>
</msg_out:Days>
<msg_out:PayType>
<xsl:value-of select="/msg_out:PreAuthAnet/msg_out:PayType"/>
</msg_out:PayType>
<xsl:for-each select="/msg_out:PreAuthAnet/msg_out:ChildAccount/msg_out:ChildProducts">
<msg_out:ChildProducts>
<msg_out:ProductObj>
<xsl:value-of select="msg_out:ProductObj"/>
</msg_out:ProductObj>
<msg_out:Amount>
<xsl:value-of select="msg_out:Amount"/>
</msg_out:Amount>
<msg_out:Tax>
<xsl:value-of select="msg_out:Tax"/>
</msg_out:Tax>
</msg_out:ChildProducts>
</xsl:for-each>
</msg_out:ChildAccount>
</msg_out:PreAuthAnet>
</xsl:template>
</xsl:stylesheet>
谢谢
新手。AFAICT,您想做: XSLT1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msg_out="http://www.portal.com/schemas/CRMSync">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/msg_out:PreAuthAnet">
<msg_out:PreAuthAnet>
<xsl:for-each select="msg_out:ChildAccount">
<msg_out:ChildAccount>
<msg_out:ChildAccountObj>
<xsl:value-of select="msg_out:AccountObj"/>
</msg_out:ChildAccountObj>
<msg_out:VIN>
<xsl:value-of select="msg_out:Vin"/>
</msg_out:VIN>
<msg_out:ParentAccountObj>
<xsl:value-of select="../msg_out:AccountObj"/>
</msg_out:ParentAccountObj>
<msg_out:Status>
<xsl:value-of select="../msg_out:Status"/>
</msg_out:Status>
<msg_out:ReasonCode>
<xsl:value-of select="../msg_out:ReasonCode"/>
</msg_out:ReasonCode>
<msg_out:Days>
<xsl:value-of select="../msg_out:Days"/>
</msg_out:Days>
<msg_out:PayType>
<xsl:value-of select="../msg_out:PayType"/>
</msg_out:PayType>
<xsl:for-each select="msg_out:ChildProducts">
<msg_out:ChildProducts>
<msg_out:ProductObj>
<xsl:value-of select="msg_out:ProductObj"/>
</msg_out:ProductObj>
<msg_out:Amount>
<xsl:value-of select="msg_out:Amount"/>
</msg_out:Amount>
<msg_out:Tax>
<xsl:value-of select="msg_out:Tax"/>
</msg_out:Tax>
</msg_out:ChildProducts>
</xsl:for-each>
</msg_out:ChildAccount>
</xsl:for-each>
</msg_out:PreAuthAnet>
</xsl:template>
</xsl:stylesheet>
或者,更优雅一点:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msg_out="http://www.portal.com/schemas/CRMSync">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/msg_out:PreAuthAnet">
<xsl:variable name="common">
<msg_out:ParentAccountObj>
<xsl:value-of select="msg_out:AccountObj"/>
</msg_out:ParentAccountObj>
<msg_out:Status>
<xsl:value-of select="msg_out:Status"/>
</msg_out:Status>
<msg_out:ReasonCode>
<xsl:value-of select="msg_out:ReasonCode"/>
</msg_out:ReasonCode>
<msg_out:Days>
<xsl:value-of select="msg_out:Days"/>
</msg_out:Days>
<msg_out:PayType>
<xsl:value-of select="msg_out:PayType"/>
</msg_out:PayType>
</xsl:variable>
<msg_out:PreAuthAnet>
<xsl:for-each select="msg_out:ChildAccount">
<msg_out:ChildAccount>
<msg_out:ChildAccountObj>
<xsl:value-of select="msg_out:AccountObj"/>
</msg_out:ChildAccountObj>
<msg_out:VIN>
<xsl:value-of select="msg_out:Vin"/>
</msg_out:VIN>
<xsl:copy-of select="$common"/>
<xsl:for-each select="msg_out:ChildProducts">
<msg_out:ChildProducts>
<msg_out:ProductObj>
<xsl:value-of select="msg_out:ProductObj"/>
</msg_out:ProductObj>
<msg_out:Amount>
<xsl:value-of select="msg_out:Amount"/>
</msg_out:Amount>
<msg_out:Tax>
<xsl:value-of select="msg_out:Tax"/>
</msg_out:Tax>
</msg_out:ChildProducts>
</xsl:for-each>
</msg_out:ChildAccount>
</xsl:for-each>
</msg_out:PreAuthAnet>
</xsl:template>
</xsl:stylesheet>
注意: 当您这样做时:
<xsl:for-each select="/msg_out:PreAuthAnet/msg_out:ChildAccount/msg_out:ChildProducts">
您正在从根开始选择整个输入文档中的所有子产品元素 您显示的预期输出不是格式良好的XML。抱歉,我忘记了第二个子帐户的结束标记。谢谢,迈克尔,这很有帮助。