我正在以下面定義的格式接收XML。我正在編寫一些代碼來轉換XML,只有特定的節點纔會變平。XSLT將扁平化特定的XML節點
<TransactionRequest>
<OrderRequests>
<OrderRequest>
<ReferenceNumber>1234567</ReferenceNumber>
<TransactionTime>2010-11-16T00:00:00-08:00</TransactionTime>
<IsRush>true</IsRush>
<ShippingAddress>
<Name>Tom Hanks</Name>
<Address1>1123 Canada Way</Address1>
<City>Burnaby</City>
<Province>BC</Province>
<PostalCode>V3B13B</PostalCode>
<HomePhone>6048871121</HomePhone>
<BusinessPhone>6041232342</BusinessPhone>
</ShippingAddress>
<ProgramType>C2</ProgramType>
<Comments>Deliver to the receptionist</Comments>
<Items>
<Item>
<Sku>UN10004</Sku>
<Quantity>2</Quantity>
</Item>
<Item>
<Sku>UN980011</Sku>
<Quantity>1</Quantity>
</Item>
</Items>
</OrderRequest>
</OrderRequests>
<TraceRequests>
<TraceRequest>
<ReferenceNumber>23432345</ReferenceNumber>
<TransactionTime>2010-11-16T00:00:00-08:00</TransactionTime>
<OriginalReferenceNumber>1234567</OriginalReferenceNumber>
<Comments>Trace Items</Comments>
<TraceItems>
<TraceItem>
<Sku>UN10004</Sku>
<Quantity>2</Quantity>
<ShipmentNumber>CM88888990</ShipmentNumber>
</TraceItem>
<TraceItem>
<Sku>UN980011</Sku>
<ProductCode>AA0091</ProductCode>
<Quantity>1</Quantity>
<ShipmentNumber>DDP123123123</ShipmentNumber>
</TraceItem>
</TraceItems>
</TraceRequest>
</TraceRequests>
</TransactionRequest>
我希望結果看起來像下面的XML。不同的是,在這個XML中,通過爲每個Items/Item複製父信息一次,TraceRequest節點將每個Items/Item節點拆分一個節點。
<?xml version="1.0"?>
<TransactionRequest>
<OrderRequests>
<OrderRequest>
<ReferenceNumber>1234567</ReferenceNumber>
<TransactionTime>2010-11-16T00:00:00-08:00</TransactionTime>
<IsRush>true</IsRush>
<ShippingAddress>
<Name>Tom Hanks</Name>
<Address1>1123 Canada Way</Address1>
<City>Burnaby</City>
<Province>BC</Province>
<PostalCode>V3B13B</PostalCode>
<HomePhone>6048871121</HomePhone>
<BusinessPhone>6041232342</BusinessPhone>
</ShippingAddress>
<ProgramType>C2</ProgramType>
<Comments>Deliver to the receptionist</Comments>
<Items>
<Item>
<Sku>UN10004</Sku>
<Quantity>2</Quantity>
</Item>
<Item>
<Sku>UN980011</Sku>
<Quantity>1</Quantity>
</Item>
</Items>
</OrderRequest>
</OrderRequests>
<TraceRequests>
<TraceRequest>
<ReferenceNumber>23432345</ReferenceNumber>
<TransactionTime>2010-11-16T00:00:00-08:00</TransactionTime>
<OriginalReferenceNumber>1234567</OriginalReferenceNumber>
<Comments>Trace Items</Comments>
<Sku>UN10004</Sku>
<Quantity>2</Quantity>
<ShipmentNumber>CM88888990</ShipmentNumber>
</TraceRequest>
<TraceRequest>
<ReferenceNumber>23432345</ReferenceNumber>
<TransactionTime>2010-11-16T00:00:00-08:00</TransactionTime>
<OriginalReferenceNumber>1234567</OriginalReferenceNumber>
<Comments>Trace Items</Comments>
<Sku>UN980011</Sku>
<ProductCode>AA0091</ProductCode>
<Quantity>1</Quantity>
<ShipmentNumber>DDP123123123</ShipmentNumber>
</TraceRequest>
</TraceRequests>
</TransactionRequest>
我似乎無法生成一個XSLT來只展平TraceRequest元素的特定子節點元素。