我有一个xml:
<ShipmentUnit>
<TrackingID>101012163322</TrackingID>
<ShipUnitSequenceID>5</ShipUnitSequenceID>
<Type>CRDCRT</Type>
<DocumentReference type="parentUnit">
<DocumentID>
<ID>101012163322</ID>
</DocumentID>
</DocumentReference>
<PointOfStagingCode>KRD001000000</PointOfStagingCode>
</ShipmentUnit>
<ShipmentUnit>
<TrackingID>101012163322</TrackingID>
<ShipUnitSequenceID>7</ShipUnitSequenceID>
<Type>CRDCRT</Type>
<DocumentReference type="parentUnit">
<DocumentID>
<ID>101012163322</ID>
</DocumentID>
</DocumentReference>
<PointOfStagingCode>KRD001000000</PointOfStagingCode>
</ShipmentUnit>
<ShipmentUnit>
<TrackingID>101012163346</TrackingID>
<ShipUnitSequenceID>9</ShipUnitSequenceID>
<Type>CRDCRT</Type>
<PointOfStagingCode>KRD001000000</PointOfStagingCode>
</ShipmentUnit>
我想组成一个小组:
<xsl:for-each-group select="ShipmentUnit" group-by="DocumentReference[@type='parentUnit']/DocumentID/ID">
问题是当XML没有group-by
节点for-each-group
忽略该XML节点时。
如何包含节点
<ShipmentUnit>
<TrackingID>101012163346</TrackingID>
<ShipUnitSequenceID>9</ShipUnitSequenceID>
<Type>CRDCRT</Type>
<PointOfStagingCode>KRD001000000</PointOfStagingCode>
</ShipmentUnit>
无论如何到for-each-group
结果?
答案 0 :(得分:2)
尝试
group-by="(DocumentReference[@type='parentUnit']/DocumentID/ID, '*')[1]"
没有文档ID的元素将形成自己的组,其分组键为“*”。
如果您希望每个此类文档都属于它自己的组,您可以使用generate-id()代替'*'。
答案 1 :(得分:1)
您可以使用group-by="string(DocumentReference[@type='parentUnit']/DocumentID/ID)"
确保不存在的节点使用分组键创建空字符串。