我有一個輸入XML,它看起來像這樣,並希望使用XSL轉換如下所示的所需輸出。我一直在瀏覽博客,但找不到與如何刪除與根元素匹配的空標籤而不是子節點的任何相關信息。僅剝離空根元素
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="urn:sobject.partner.soap.sforce.com">
<Revenue__c/>
<Revenue__c/>
<Revenue__c/>
<Revenue__c>
<Sales_Org_ID__c>IV</Sales_Org_ID__c>
<Branch_ID__c>1</Branch_ID__c>
<Branch_Name__c>TEST</Branch_Name__c>
<Therapy_Code__c>TEST</Therapy_Code__c>
<Therapy_Name__c>TEST</Therapy_Name__c>
<Therapy_Class_Code__c>TEST</Therapy_Class_Code__c>
<Therapy_Class_Name__c>TEST</Therapy_Class_Name__c>
<Payor_Type_Name__c>TEST</Payor_Type_Name__c>
<Calendar_Year_Number__c>2011</Calendar_Year_Number__c>
<Month_Revenue_Amount__c>100.01</Month_Revenue_Amount__c>
<Payor_ID__c>TEST</Payor_ID__c>
<Payor_Name__c/>
<Payor_Type_Code__c>TEST</Payor_Type_Code__c>
<MDM_Account_EID__c>66600001</MDM_Account_EID__c>
<MDM_Physician_EID__c>99900001</MDM_Physician_EID__c>
<Account__c>001a000001APU5OAAX</Account__c>
<Contact__c>003a000001RL1EFAA1</Contact__c>
<Revenue_ID__c>41</Revenue_ID__c>
<Calendar_Year_Month__c>01</Calendar_Year_Month__c>
</Revenue__c>
</objects>
這正是我想要的了:
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="urn:sobject.partner.soap.sforce.com">
<Revenue__c>
<Sales_Org_ID__c>IV</Sales_Org_ID__c>
<Branch_ID__c>1</Branch_ID__c>
<Branch_Name__c>TEST</Branch_Name__c>
<Therapy_Code__c>TEST</Therapy_Code__c>
<Therapy_Name__c>TEST</Therapy_Name__c>
<Therapy_Class_Code__c>TEST</Therapy_Class_Code__c>
<Therapy_Class_Name__c>TEST</Therapy_Class_Name__c>
<Payor_Type_Name__c>TEST</Payor_Type_Name__c>
<Calendar_Year_Number__c>2011</Calendar_Year_Number__c>
<Month_Revenue_Amount__c>100.01</Month_Revenue_Amount__c>
<Payor_ID__c>TEST</Payor_ID__c>
<Payor_Name__c/>
<Payor_Type_Code__c>TEST</Payor_Type_Code__c>
<MDM_Account_EID__c>66600001</MDM_Account_EID__c>
<MDM_Physician_EID__c>99900001</MDM_Physician_EID__c>
<Account__c>001a000001APU5OAAX</Account__c>
<Contact__c>003a000001RL1EFAA1</Contact__c>
<Revenue_ID__c>41</Revenue_ID__c>
<Calendar_Year_Month__c>01</Calendar_Year_Month__c>
</Revenue__c>
</objects>
任何建議將不勝感激。
要點澄清......空' '元素不是「根元素」。 「根」是指文檔的最外層。 ' '元素有一個父親'
哦,也許你的意思是「葉元素」,也就是沒有孩子的元素。 (「葉節點」是圖論和CS中的一個通用術語,但不是特別的XML,不像「根節點」。) – LarsH