我必须转换输入 xml,
<?xml version="1.0" encoding="UTF-8" ?>
<queryResponse xmlns="urn:partner.soap.sforce.com">
<result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="QueryResult">
<records xmlns:sf="urn:sobject.partner.soap.sforce.com" xsi:type="sf:sObject">
<sf:type>Course__c</sf:type>
<sf:Id>a0c20000002Yu</sf:Id>
<sf:Id>a0c20000002Yu</sf:Id>
<sf:CurrencyIsoCode>USD</sf:CurrencyIsoCode>
<sf:Course_End_Time__c>5 pm</sf:Course_End_Time__c>
<sf:Course_Start_Time__c>8 am</sf:Course_Start_Time__c>
<sf:Course_Type__c>Face to Face</sf:Course_Type__c>
</records>
<records xmlns:sf="urn:sobject.partner.soap.sforce.com" xsi:type="sf:sObject">
<sf:type>Course__c</sf:type>
<sf:Id>a0c20000002ZI</sf:Id>
<sf:Id>a0c20000002ZI</sf:Id>
<sf:CurrencyIsoCode>AUD</sf:CurrencyIsoCode>
<sf:Course_End_Time__c>5:00PM</sf:Course_End_Time__c>
<sf:Course_Start_Time__c>9:00AM</sf:Course_Start_Time__c>
<sf:Course_Type__c>Face to Face</sf:Course_Type__c>
</records>
</result>
<Information xmlns="http://ws.apache.org/ns/synapse" xmlns:ns="www.abc.com">
<queryResponse xmlns="urn:partner.soap.sforce.com">
<result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="QueryResult">
<done>true</done>
<queryLocator xsi:nil="true"/>
<records xsi:type="sf:sObject">
<sf:Class_Begin_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-04-09</sf:Class_Begin_Date__c>
<sf:Class_End_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-04-10</sf:Class_End_Date__c>
<sf:Class_Location__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Other</sf:Class_Location__c>
<sf:Class_Status__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Closed</sf:Class_Status__c>
<sf:Course_Name__c xmlns:sf="urn:sobject.partner.soap.sforce.com">a0c20000002Yu</sf:Course_Name__c>
<sf:Display_on_the_Website__c xmlns:sf="urn:sobject.partner.soap.sforce.com">false</sf:Display_on_the_Website__c>
<sf:Maximum_Attendee__c xmlns:sf="urn:sobject.partner.soap.sforce.com">10.0</sf:Maximum_Attendee__c>
<sf:Number_of_Confirmed_Attendees__c xmlns:sf="urn:sobject.partner.soap.sforce.com">8.0</sf:Number_of_Confirmed_Attendees__c>
<sf:Placements_Available__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2.0</sf:Placements_Available__c>
</records>
<size>1</size>
</result>
</queryResponse>
<queryResponse xmlns="urn:partner.soap.sforce.com">
<result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="QueryResult">
<queryResponse xmlns="urn:partner.soap.sforce.com">
<result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="QueryResult">
<done>true</done>
<queryLocator xsi:nil="true"/>
<records xsi:type="sf:sObject">
<sf:Class_Begin_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-02-07</sf:Class_Begin_Date__c>
<sf:Class_End_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-02-08</sf:Class_End_Date__c>
<sf:Class_Location__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Other</sf:Class_Location__c>
<sf:Class_Status__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Open</sf:Class_Status__c>
<sf:Course_Name__c xmlns:sf="urn:sobject.partner.soap.sforce.com">a0c20000002ZI</sf:Course_Name__c>
<sf:Display_on_the_Website__c xmlns:sf="urn:sobject.partner.soap.sforce.com">false</sf:Display_on_the_Website__c>
<sf:Maximum_Attendee__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Maximum_Attendee__c>
<sf:Number_of_Confirmed_Attendees__c xmlns:sf="urn:sobject.partner.soap.sforce.com">0.0</sf:Number_of_Confirmed_Attendees__c>
<sf:Placements_Available__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Placements_Available__c>
</records>
<records xsi:type="sf:sObject">
<sf:Class_Begin_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-01-31</sf:Class_Begin_Date__c>
<sf:Class_End_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-01-31</sf:Class_End_Date__c>
<sf:Class_Location__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Canberra</sf:Class_Location__c>
<sf:Class_Status__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Open</sf:Class_Status__c>
<sf:Course_Name__c xmlns:sf="urn:sobject.partner.soap.sforce.com">a0c20000002ZI</sf:Course_Name__c>
<sf:Display_on_the_Website__c xmlns:sf="urn:sobject.partner.soap.sforce.com">false</sf:Display_on_the_Website__c>
<sf:Maximum_Attendee__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Maximum_Attendee__c>
<sf:Number_of_Confirmed_Attendees__c xmlns:sf="urn:sobject.partner.soap.sforce.com">0.0</sf:Number_of_Confirmed_Attendees__c>
<sf:Placements_Available__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Placements_Available__c>
</records>
<records xsi:type="sf:sObject">
<sf:Class_Begin_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-02-17</sf:Class_Begin_Date__c>
<sf:Class_End_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-02-17</sf:Class_End_Date__c>
<sf:Class_Location__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Other</sf:Class_Location__c>
<sf:Class_Status__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Open</sf:Class_Status__c>
<sf:Course_Name__c xmlns:sf="urn:sobject.partner.soap.sforce.com">a0c20000002ZI</sf:Course_Name__c>
<sf:Display_on_the_Website__c xmlns:sf="urn:sobject.partner.soap.sforce.com">false</sf:Display_on_the_Website__c>
<sf:Maximum_Attendee__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Maximum_Attendee__c>
<sf:Number_of_Confirmed_Attendees__c xmlns:sf="urn:sobject.partner.soap.sforce.com">0.0</sf:Number_of_Confirmed_Attendees__c>
<sf:Placements_Available__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Placements_Available__c>
</records>
<records xsi:type="sf:sObject">
<sf:Class_Begin_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-03-13</sf:Class_Begin_Date__c>
<sf:Class_End_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-03-15</sf:Class_End_Date__c>
<sf:Class_Location__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Other</sf:Class_Location__c>
<sf:Class_Status__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Open</sf:Class_Status__c>
<sf:Course_Name__c xmlns:sf="urn:sobject.partner.soap.sforce.com">a0c20000002ZI</sf:Course_Name__c>
<sf:Display_on_the_Website__c xmlns:sf="urn:sobject.partner.soap.sforce.com">false</sf:Display_on_the_Website__c>
<sf:Maximum_Attendee__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Maximum_Attendee__c>
<sf:Number_of_Confirmed_Attendees__c xmlns:sf="urn:sobject.partner.soap.sforce.com">0.0</sf:Number_of_Confirmed_Attendees__c>
<sf:Placements_Available__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Placements_Available__c>
</records>
<records xsi:type="sf:sObject">
<sf:Class_Begin_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-03-07</sf:Class_Begin_Date__c>
<sf:Class_End_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-03-11</sf:Class_End_Date__c>
<sf:Class_Location__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Other</sf:Class_Location__c>
<sf:Class_Status__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Open</sf:Class_Status__c>
<sf:Course_Name__c xmlns:sf="urn:sobject.partner.soap.sforce.com">a0c20000002ZI</sf:Course_Name__c>
<sf:Display_on_the_Website__c xmlns:sf="urn:sobject.partner.soap.sforce.com">false</sf:Display_on_the_Website__c>
<sf:Maximum_Attendee__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Maximum_Attendee__c>
<sf:Number_of_Confirmed_Attendees__c xmlns:sf="urn:sobject.partner.soap.sforce.com">0.0</sf:Number_of_Confirmed_Attendees__c>
<sf:Placements_Available__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Placements_Available__c>
</records>
<size>5</size>
</result>
</queryResponse>
</result>
</queryResponse>
</Information>
</queryResponse>
转换为以下输出格式。
<queryResponse xmlns="urn:partner.soap.sforce.com">
<result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="QueryResult">
<done>true</done>
<queryLocator xsi:nil="true"/>
<records xmlns:sf="urn:sobject.partner.soap.sforce.com" xsi:type="sf:sObject">
<sf:type>Course__c</sf:type>
<sf:Id>a0c20000002Yu</sf:Id>
<sf:Id>a0c20000002Yu</sf:Id>
<sf:CurrencyIsoCode>USD</sf:CurrencyIsoCode>
<sf:Course_End_Time__c>5 pm</sf:Course_End_Time__c>
<sf:Course_Start_Time__c>8 am</sf:Course_Start_Time__c>
<sf:Course_Type__c>Face to Face</sf:Course_Type__c>
<classes>
<class>
<sf:Class_Begin_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-04-09</sf:Class_Begin_Date__c>
<sf:Class_End_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-04-10</sf:Class_End_Date__c>
<sf:Class_Location__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Other</sf:Class_Location__c>
<sf:Class_Status__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Closed</sf:Class_Status__c>
<sf:Course_Name__c xmlns:sf="urn:sobject.partner.soap.sforce.com">a0c20000002Yu</sf:Course_Name__c>
<sf:Display_on_the_Website__c xmlns:sf="urn:sobject.partner.soap.sforce.com">false</sf:Display_on_the_Website__c>
<sf:Maximum_Attendee__c xmlns:sf="urn:sobject.partner.soap.sforce.com">10.0</sf:Maximum_Attendee__c>
<sf:Number_of_Confirmed_Attendees__c xmlns:sf="urn:sobject.partner.soap.sforce.com">8.0</sf:Number_of_Confirmed_Attendees__c>
<sf:Placements_Available__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2.0</sf:Placements_Available__c>
</class>
</classes>
</records>
<records xsi:type="sf:sObject" xmlns:sf="urn:sobject.partner.soap.sforce.com">
<sf:type>Course__c</sf:type>
<sf:Id>a0c20000002ZI</sf:Id>
<sf:Id>a0c20000002ZI</sf:Id>
<sf:CurrencyIsoCode>AUD</sf:CurrencyIsoCode>
<sf:Course_End_Time__c>5:00PM</sf:Course_End_Time__c>
<sf:Course_Start_Time__c>9:00AM</sf:Course_Start_Time__c>
<sf:Course_Type__c>Face to Face</sf:Course_Type__c>
<classes>
<class>
<sf:Class_Begin_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-02-07</sf:Class_Begin_Date__c>
<sf:Class_End_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-02-08</sf:Class_End_Date__c>
<sf:Class_Location__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Other</sf:Class_Location__c>
<sf:Class_Status__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Open</sf:Class_Status__c>
<sf:Course_Name__c xmlns:sf="urn:sobject.partner.soap.sforce.com">a0c20000002ZI</sf:Course_Name__c>
<sf:Display_on_the_Website__c xmlns:sf="urn:sobject.partner.soap.sforce.com">false</sf:Display_on_the_Website__c>
<sf:Maximum_Attendee__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Maximum_Attendee__c>
<sf:Number_of_Confirmed_Attendees__c xmlns:sf="urn:sobject.partner.soap.sforce.com">0.0</sf:Number_of_Confirmed_Attendees__c>
<sf:Placements_Available__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Placements_Available__c>
</class>
<class>
<sf:Class_Begin_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-01-31</sf:Class_Begin_Date__c>
<sf:Class_End_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-01-31</sf:Class_End_Date__c>
<sf:Class_Location__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Canberra</sf:Class_Location__c>
<sf:Class_Status__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Open</sf:Class_Status__c>
<sf:Course_Name__c xmlns:sf="urn:sobject.partner.soap.sforce.com">a0c20000002ZI</sf:Course_Name__c>
<sf:Display_on_the_Website__c xmlns:sf="urn:sobject.partner.soap.sforce.com">false</sf:Display_on_the_Website__c>
<sf:Maximum_Attendee__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Maximum_Attendee__c>
<sf:Number_of_Confirmed_Attendees__c xmlns:sf="urn:sobject.partner.soap.sforce.com">0.0</sf:Number_of_Confirmed_Attendees__c>
<sf:Placements_Available__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Placements_Available__c>
</class>
<class>
<sf:Class_Begin_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-02-17</sf:Class_Begin_Date__c>
<sf:Class_End_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-02-17</sf:Class_End_Date__c>
<sf:Class_Location__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Other</sf:Class_Location__c>
<sf:Class_Status__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Open</sf:Class_Status__c>
<sf:Course_Name__c xmlns:sf="urn:sobject.partner.soap.sforce.com">a0c20000002ZI</sf:Course_Name__c>
<sf:Display_on_the_Website__c xmlns:sf="urn:sobject.partner.soap.sforce.com">false</sf:Display_on_the_Website__c>
<sf:Maximum_Attendee__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Maximum_Attendee__c>
<sf:Number_of_Confirmed_Attendees__c xmlns:sf="urn:sobject.partner.soap.sforce.com">0.0</sf:Number_of_Confirmed_Attendees__c>
<sf:Placements_Available__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Placements_Available__c>
</class>
<class>
<sf:Class_Begin_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-03-13</sf:Class_Begin_Date__c>
<sf:Class_End_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-03-15</sf:Class_End_Date__c>
<sf:Class_Location__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Other</sf:Class_Location__c>
<sf:Class_Status__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Open</sf:Class_Status__c>
<sf:Course_Name__c xmlns:sf="urn:sobject.partner.soap.sforce.com">a0c20000002ZI</sf:Course_Name__c>
<sf:Display_on_the_Website__c xmlns:sf="urn:sobject.partner.soap.sforce.com">false</sf:Display_on_the_Website__c>
<sf:Maximum_Attendee__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Maximum_Attendee__c>
<sf:Number_of_Confirmed_Attendees__c xmlns:sf="urn:sobject.partner.soap.sforce.com">0.0</sf:Number_of_Confirmed_Attendees__c>
<sf:Placements_Available__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Placements_Available__c>
</class>
<class>
<sf:Class_Begin_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-03-07</sf:Class_Begin_Date__c>
<sf:Class_End_Date__c xmlns:sf="urn:sobject.partner.soap.sforce.com">2012-03-11</sf:Class_End_Date__c>
<sf:Class_Location__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Other</sf:Class_Location__c>
<sf:Class_Status__c xmlns:sf="urn:sobject.partner.soap.sforce.com">Open</sf:Class_Status__c>
<sf:Course_Name__c xmlns:sf="urn:sobject.partner.soap.sforce.com">a0c20000002ZI</sf:Course_Name__c>
<sf:Display_on_the_Website__c xmlns:sf="urn:sobject.partner.soap.sforce.com">false</sf:Display_on_the_Website__c>
<sf:Maximum_Attendee__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Maximum_Attendee__c>
<sf:Number_of_Confirmed_Attendees__c xmlns:sf="urn:sobject.partner.soap.sforce.com">0.0</sf:Number_of_Confirmed_Attendees__c>
<sf:Placements_Available__c xmlns:sf="urn:sobject.partner.soap.sforce.com">40.0</sf:Placements_Available__c>
</class>
</classes>
</records>
</result>
</queryResponse>
为此,我尝试调整一个简单的示例 [1] 中给出的 xslt。我的 xslt 看起来像这样。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:syn="http://ws.apache.org/ns/synapse"
exclude-result-prefixes="syn" xmlns:sf="urn:sobject.partner.soap.sforce.com"
xmlns:sfrsp="urn:partner.soap.sforce.com">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes" />
<xsl:strip-space elements="*" />
<xsl:key name="child"
match="//sfrsp:queryResponse/syn:Information/sfrsp:queryResponse[1]/sfrsp:result/sfrsp:records[1]"
use="//sfrsp:queryResponse/syn:Information/sfrsp:queryResponse[1]/sfrsp:result/sfrsp:records[1]/sf:Course_Name__c" />
<xsl:template match="@*|node()">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="//sfrsp:queryResponse/sfrsp:result/sfrsp:records[1]">
<xsl:copy>
<xsl:apply-templates />
<Children>
<xsl:apply-templates
select="key('child', //sfrsp:queryResponse/sfrsp:result/sfrsp:records[1]/sf:Id[1])" />
</Children>
</xsl:copy>
</xsl:template>
<xsl:template match="syn:Information" />
</xsl:stylesheet>
但它不会按预期转换 XML。任何帮助将不胜感激。所有Course_Name__c与父元素的 Id 值相似的子元素都需要位于父元素下。
[1] 使用 XSLT 关联相关项目
对于键用途是匹配的元素上下文节点。因此,请尝试将密钥更改为:
<xsl:key name="child"
match="//sfrsp:queryResponse/syn:Information/sfrsp:queryResponse[1]/sfrsp:result/sfrsp:records[1]"
use="sf:Course_Name__c" />
而不是将其用作:
<xsl:apply-templates
select="key('child', sf:Id[1])" />