请遵循示例 xml 中的注释,它解释了我需要的所有内容,它有三个场景以相同的顺序检查输出 xml 中的每个场景。
输入 XML
<!-- In the below xml there will be one ASNInDesc with multiple ASNInPO's
and each ASNInPO contains one ASNInCtn and each ASNInCtn contains one ASNInItem -->
<ASNInDesc>
<asn_nbr>ASN-1</asn_nbr>
<!-- In the below two ASNInPO's po_nbr is same container_id under ASNInCtn is same and item_id under
ASNInItem is same. In this case two ASNInPO's has to be merged and two ASNInCtn's has to be merged
into one tag(since the container_id is same) and two ASNInItem's has to be merged into one tag and unit_qty is to be added -->
<ASNInPO>
<po_nbr>PO-1</po_nbr>
<ASNInCtn>
<container_id>CONTAINER-1</container_id>
<ASNInItem>
<item_id>ITEM-1</item_id>
<unit_qty>2</unit_qty>
</ASNInItem>
</ASNInCtn>
</ASNInPO>
<ASNInPO>
<po_nbr>PO-1</po_nbr>
<ASNInCtn>
<container_id>CONTAINER-1</container_id>
<ASNInItem>
<item_id>ITEM-1</item_id>
<unit_qty>2</unit_qty>
</ASNInItem>
</ASNInCtn>
</ASNInPO>
<!-- In the below two ASNInPO's po_nbr is same container_id under ASNInCtn is same and item_id under
ASNInItem is different. In this case two ASNInPO's has to be merged and two ASNInCtn's has to be merged into one tag and
two different ASNInItem's for the two different items -->
<ASNInPO>
<po_nbr>PO-2</po_nbr>
<ASNInCtn>
<container_id>CONTAINER-2</container_id>
<ASNInItem>
<item_id>ITEM-2</item_id>
<unit_qty>3</unit_qty>
</ASNInItem>
</ASNInCtn>
</ASNInPO>
<ASNInPO>
<po_nbr>PO-2</po_nbr>
<ASNInCtn>
<container_id>CONTAINER-2</container_id>
<ASNInItem>
<item_id>ITEM-3</item_id>
<unit_qty>3</unit_qty>
</ASNInItem>
</ASNInCtn>
</ASNInPO>
<!-- In the below two ASNInPO's po_nbr is same container_id under ASNInCtn is different and item_id under
ASNInItem is different. In this case two ASNInPO's has to be merged into one tag with
two different ASNInCtn's each having their own ASNInItem -->
<ASNInPO>
<po_nbr>PO-3</po_nbr>
<ASNInCtn>
<container_id>CONTAINER-3</container_id>
<ASNInItem>
<item_id>ITEM-3</item_id>
<unit_qty>2</unit_qty>
</ASNInItem>
</ASNInCtn>
</ASNInPO>
<ASNInPO>
<po_nbr>PO-3</po_nbr>
<ASNInCtn>
<container_id>CONTAINER-4</container_id>
<ASNInItem>
<item_id>ITEM-3</item_id>
<unit_qty>2</unit_qty>
</ASNInItem>
</ASNInCtn>
</ASNInPO>
</ASNInDesc>
输出 XML
<?xml version = '1.0' encoding = 'UTF-8'?>
<ASNInDesc>
<asn_nbr>ASN-1</asn_nbr>
<!-- Scenerio-1 -->
<ASNInPO>
<po_nbr>PO-1</po_nbr>
<ASNInCtn>
<container_id>CONTAINER-1</container_id>
<ASNInItem>
<item_id>ITEM-1</item_id>
<unit_qty>4</unit_qty>
</ASNInItem>
</ASNInCtn>
</ASNInPO>
<!-- Scenerio-2 -->
<ASNInPO>
<po_nbr>PO-2</po_nbr>
<ASNInCtn>
<container_id>CONTAINER-2</container_id>
<ASNInItem>
<item_id>ITEM-2</item_id>
<unit_qty>3</unit_qty>
</ASNInItem>
<ASNInItem>
<item_id>ITEM-3</item_id>
<unit_qty>3</unit_qty>
</ASNInItem>
</ASNInCtn>
</ASNInPO>
<!-- Scenerio-3 -->
<ASNInPO>
<po_nbr>PO-3</po_nbr>
<ASNInCtn>
<container_id>CONTAINER-3</container_id>
<ASNInItem>
<item_id>ITEM-3</item_id>
<unit_qty>2</unit_qty>
</ASNInItem>
</ASNInCtn>
<ASNInCtn>
<container_id>CONTAINER-4</container_id>
<ASNInItem>
<item_id>ITEM-3</item_id>
<unit_qty>2</unit_qty>
</ASNInItem>
</ASNInCtn>
</ASNInPO>
我尝试过使用自己的 xsl,但无法处理所有场景。请帮我解决这个问题。提前致谢。