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