0
我已阅读过有关我能找到的所有内容,但尚未找到使其正常工作的方法。我试图根据节点或其父节点的值从特定节点查询总和。有些节点可能符合具有正确名称的基本要求,但其父母可能不会,所以我需要忽略这些。在SQL术语中,我会用EXISTS或LIKE子句来解决这个问题。XPath,基于相关节点的过滤器
我试图做的是
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)
也许这ISN”可能。我不能做的一件事是改变模式/数据结构。
感谢您的答复马特。我修复了XML,对于结束标记感到抱歉。 我试过你在XML Spy中的解决方案,它不喜欢它。试过调整它,并不能到达那里,但在VS2010中它是一个宾果游戏。有一天我可能会对此语法有所了解。非常感谢! – Rick 2013-03-14 17:06:19