0
我是XSLT新手,正試圖將以下XML轉換爲下一個XML。我已經評論了第二個XML中需要的重大更改。XSLT幫助 - 將屬性轉換爲元素並重命名元素
有2度主要的改變:
1)由於節點2元件名重複,我要重命名的第二次出現。 2)我希望itemName屬性每個成爲一個元素。 2a)對於[客戶ID] itemValue,我需要在將其轉換爲元素時將其重命名爲'CustomerID'。
總之,我希望原件在瀏覽器中呈現後轉換爲更像表格的柱狀結構。
<requestStatus>
<node1>
<clientId>4634</clientId>
<affiliateId>0</affiliateId>
<contactId>144756</contactId>
<requestId>64086</requestId>
<transNumber>F27A6A65</transNumber>
<status>11</status>
<paymentType>D</paymentType>
<amount>1.99</amount>
<contactEmail>[email protected]</contactEmail>
<templateName>Payment Form 2</templateName>
<createdBy>0</createdBy>
<paymentCnt>1</paymentCnt>
<nextPaymtDate/>
<recurringFrequency/>
<maxPayments>0</maxPayments>
<untilDate/>
<node2>
<node2>
<paymtId>56991</paymtId>
<paidAmount>1.99</paidAmount>
<paymentMethod>C</paymentMethod>
<paymentSeq>1</paymentSeq>
<submissionDate>08/04/2016</submissionDate>
<creditCardType>V</creditCardType>
<creditCardNumber>1111</creditCardNumber>
<cardHolder>Ronald McDonald</cardHolder>
<expirationMonth>1</expirationMonth>
<expirationYear>2017</expirationYear>
<achRequestId>0</achRequestId>
<accountNumber/>
<accountType/>
<depositType/>
<achSubmissionDate/>
<achEffectiveDate/>
</node2>
</node2>
<node3>
<node4>
<itemName>[FirstName]</itemName>
<itemValue>Ronald</itemValue>
</node4>
<node4>
<itemName>[LastName]</itemName>
<itemValue>McDonald</itemValue>
</node4>
<node4>
<itemName>[Email]</itemName>
<itemValue>[email protected]</itemValue>
</node4>
<node4>
<itemName>[Amount]</itemName>
<itemValue>1.99</itemValue>
</node4>
<node4>
<itemName>Customer ID</itemName>
<itemValue>CUSTOMER1</itemValue>
</node4>
<node4>
<itemName>Invoice Numbers</itemName>
<itemValue>INV10001,INV10002</itemValue>
</node4>
</node3>
</node1>
</requestStatus>
To this:
<requestStatus>
<node1>
<clientId>4634</clientId>
<affiliateId>0</affiliateId>
<contactId>144756</contactId>
<requestId>64086</requestId>
<transNumber>F27A6A65</transNumber>
<status>11</status>
<paymentType>D</paymentType>
<amount>1.99</amount>
<contactEmail>[email protected]</contactEmail>
<templateName>Payment Form 2</templateName>
<createdBy>0</createdBy>
<paymentCnt>1</paymentCnt>
<nextPaymtDate/>
<recurringFrequency/>
<maxPayments>0</maxPayments>
<untilDate/>
<node2>
<node2b> <!-- since node2 element was repeated, rename this as node2b -->
<paymtId>56991</paymtId>
<paidAmount>1.99</paidAmount>
<paymentMethod>C</paymentMethod>
<paymentSeq>1</paymentSeq>
<submissionDate>08/04/2016</submissionDate>
<creditCardType>V</creditCardType>
<creditCardNumber>1111</creditCardNumber>
<cardHolder>Ronald McDonald</cardHolder>
<expirationMonth>1</expirationMonth>
<expirationYear>2017</expirationYear>
<achRequestId>0</achRequestId>
<accountNumber/>
<accountType/>
<depositType/>
<achSubmissionDate/>
<achEffectiveDate/>
</node2b>
</node2>
<node3>
<FirstName>Ronald</FirstName> <!-- each itemName attribute to become a unique Element -->
<LastName>McDonald</LastName>
<Email>[email protected]</Email>
<Amount>1.99</Amount>
<CustomerID>CUSTOMER1</CustomerID>
<InvoiceNumbers>INV10001,INV10002</InvoiceNumbers>
</node3>
</node1>
你不想編號的節點名稱,你嚴重不。重新考慮你的佈局。 – Tomalak
實際的XML不會 - 爲了便於查看而暫時將其編號。 – user3769185
我也不贊同這一點。人們將爲沒有任何好處的編號元素編寫解決方案 - 並且您的XML不難遵循任何一種方式。 – Tomalak