我已经阅读了我能找到的所有内容,但还没有找到让它工作的方法。我正在尝试根据节点或其父节点的值从特定节点查询总和。一些节点可能满足具有正确名称的基本要求,但它们的父节点可能不满足,所以我需要忽略这些。在 SQL 术语中,我会使用 EXISTS 或 LIKE 子句来解决这个问题。
我想做的是
SUM ServiceAmounts
FROM ChargeData elements
WHERE ChargeDescription = 'subTotal-DistrubutionCharges'
AND Detail.ServiceType = 'electric'
AND NOT
(
ChargeData has a sibling with ChargeDescription = 'Leased Outdoor Lighting' - the entire detail node should be ignored that contains the ChargeData element with 'Leased Outdoor Lighting'.
)
如果有价值的话,我的 XSL 版本是 1.0。
源 XML:
<Source>
<Detail>
<ServiceType>electric</ServiceType>
<Charges>
<ChargeData>
<AllowanceChargeInd>C</AllowanceChargeInd>
<ServiceAmount>19.8</ServiceAmount>
<ChargeDescription>7% Sales Tax</ChargeDescription>
<ChargeID>sales_tax</ChargeID>
</ChargeData>
<ChargeData>
<AllowanceChargeInd>C</AllowanceChargeInd>
<ServiceAmount>282.8</ServiceAmount>
<ChargeDescription>E-2 Demand</ChargeDescription>
<ChargeID>usage_charge</ChargeID>
</ChargeData>
<ChargeData>
<AllowanceChargeInd>C</AllowanceChargeInd>
<ServiceAmount>165.91</ServiceAmount>
<ChargeDescription>7% Sales Tax</ChargeDescription>
<ChargeID>sales_tax</ChargeID>
</ChargeData>
<ChargeData>
<AllowanceChargeInd>C</AllowanceChargeInd>
<ServiceAmount>2370.15</ServiceAmount>
<ChargeDescription>E-2 Commercial</ChargeDescription>
<ChargeID>usage_charge</ChargeID>
</ChargeData>
<ChargeData>
<AllowanceChargeInd>C</AllowanceChargeInd>
<ServiceAmount>2838.66</ServiceAmount>
<Quantity>0</Quantity>
<ChargeDescription>subTotal-DistributionCharges</ChargeDescription>
</ChargeData>
</Charges>
</Detail>
<Detail>
<ServiceType>electric</ServiceType>
<Charges>
<ChargeData>
<AllowanceChargeInd>C</AllowanceChargeInd>
<ServiceAmount>2.57</ServiceAmount>
<ChargeDescription>7% Sales Tax</ChargeDescription>
<ChargeID>sales_tax</ChargeID>
</ChargeData>
<ChargeData>
<AllowanceChargeInd>C</AllowanceChargeInd>
<ServiceAmount>36.8</ServiceAmount>
<ChargeDescription>Leased Outdoor Lighting</ChargeDescription>
<ChargeID>usage_charge</ChargeID>
</ChargeData>
<ChargeData>
<AllowanceChargeInd>C</AllowanceChargeInd>
<ServiceAmount>39.37</ServiceAmount>
<Quantity>0</Quantity>
<ChargeDescription>subTotal-DistributionCharges</ChargeDescription>
</ChargeData>
</Charges>
</Detail>
</Source>
我的 xsl,好吧,我已经尝试了多次并一直陷入死胡同:
sum(//ChargeData[not(contains(ChargeDescription,'Leased Outdoor Lighting'))
and not(contains(Detail/Charges/ChargeData/ChargeDescription, 'subTotal'))
and ancestor::Detail/ServiceType='electric']/ServiceAmount)
或者
sum(//ChargeData[contains(ChargeDescription, 'subTotal-DistributionCharges')
and ancestor::Detail/ServiceType='electric']/ServiceAmount)
-
sum(//ChargeData[contains(ChargeDescription, 'Leased Outdoor Lighting')
and ancestor::Detail/ServiceType='electric']/ServiceAmount)
也许这是不可能的。我不能做的一件事是更改架构/数据结构。