刪除子節點,我有以下XML:XSLT:不重複的XPath
<?xml version="1.0"?>
<Transaction>
<Product>
<ProductRq>
<ContactInfo>
<!-- several child elements -->
</ContactInfo>
<OrderInfo>
<!-- several child elements -->
</OrderInfo>
<ProductInfo>
<!-- several child elements -->
</ProductInfo>
<AddressInfo>
<!-- several child elements -->
</AddressInfo>
<AuditInfo>
<!-- several child elements -->
</AuditInfo>
<DeliveryInfo>
<!-- several child elements -->
</DeliveryInfo>
</ProductRq>
</Product>
</Transaction>
爲簡潔起見,我已經離開了幾個孩子的<ProductRq>
標籤,它包含4個或5個以上的子元素類似於到<OrderInfo>
和<CustomerInfo>
,以及* Info元素的子節點。
我需要刪除Order和<CustomerInfo>
等元素的子元素,同時保留* Info標記。在7個標籤中,大約有4個將通過這個過程。我想不出如何不重複:
<xsl:template match="Transcation/Product/ProductRq/<tag name here>/*" />
<ProductRq>
的每個孩子。有沒有一種方法可以利用上下文節點(<ProductRq>
)和通過子節點循環的方式,從上面除去他們自己的子節點?
編輯:
我添加了<ProductRq>
的其餘子標記。除<AuditInfo>
和<ContactInfo>
之外的所有標籤必須刪除其子節點。
您實際上並不需要在模板匹配中指定完整的xpath,您可以在/*」/>'中執行。如果相同的元素可能出現在層次結構的不同級別中,並且您需要區分它們,則只需使用完整路徑對其進行限定即可。 –
好吧,我認爲ProductRq中的一些子元素可能會對文檔中的不同標記重複一次,但ProducerRq是唯一的,因此ProducerRq/就足夠了? –
jbailie1991
@ jbailie1991 - 你真的需要展示那些遺漏的孩子,因爲它們與你的問題非常相關。至少展示* ProductRq *的孩子。 – Parfait