0

我有一个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

4

2 回答 2

2

尝试

group-by="(DocumentReference[@type='parentUnit']/DocumentID/ID, '*')[1]"

没有文档 ID 的元素将组成自己的组,分组键为“*”。

如果您希望每个此类文档都属于自己的一组,则可以使用 generate-id() 代替“*”。

于 2013-09-06T10:27:34.947 回答
1

您可以确保一个不存在的节点使用创建一个空字符串作为分组键group-by="string(DocumentReference[@type='parentUnit']/DocumentID/ID)"

于 2013-09-06T11:00:04.320 回答