2014-09-22 3 views
0

У меня есть следующий XML:Исключая XPath элементы, которые имеют детей с определенным значением

<LowestOfferListings> 
    <LowestOfferListing> 
     <Qualifiers> 
     <ItemCondition>New</ItemCondition> 
     <ItemSubcondition>New</ItemSubcondition> 
     <FulfillmentChannel>Merchant</FulfillmentChannel> 
     <ShipsDomestically>True</ShipsDomestically> 
     <ShippingTime> 
      <Max>0-2 days</Max> 
     </ShippingTime> 
     <SellerPositiveFeedbackRating>95-97%</SellerPositiveFeedbackRating> 
     </Qualifiers> 
     <NumberOfOfferListingsConsidered>5</NumberOfOfferListingsConsidered> 
     <SellerFeedbackCount>9197</SellerFeedbackCount> 
     <Price> 
     <LandedPrice> 
      <CurrencyCode>JPY</CurrencyCode> 
      <Amount>1675.00</Amount> 
     </LandedPrice> 
     <ListingPrice> 
      <CurrencyCode>JPY</CurrencyCode> 
      <Amount>1275.00</Amount> 
     </ListingPrice> 
     <Shipping> 
      <CurrencyCode>JPY</CurrencyCode> 
      <Amount>400.00</Amount> 
     </Shipping> 
     </Price> 
     <MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice> 
    </LowestOfferListing> 
    <LowestOfferListing> 
     <Qualifiers> 
     <ItemCondition>New</ItemCondition> 
     <ItemSubcondition>New</ItemSubcondition> 
     <FulfillmentChannel>Merchant</FulfillmentChannel> 
     <ShipsDomestically>False</ShipsDomestically> 
     <ShippingTime> 
      <Max>0-2 days</Max> 
     </ShippingTime> 
     <SellerPositiveFeedbackRating>90-94%</SellerPositiveFeedbackRating> 
     </Qualifiers> 
     <NumberOfOfferListingsConsidered>3</NumberOfOfferListingsConsidered> 
     <SellerFeedbackCount>1430</SellerFeedbackCount> 
     <Price> 
     <LandedPrice> 
      <CurrencyCode>JPY</CurrencyCode> 
      <Amount>1820.00</Amount> 
     </LandedPrice> 
     <ListingPrice> 
      <CurrencyCode>JPY</CurrencyCode> 
      <Amount>1240.00</Amount> 
     </ListingPrice> 
     <Shipping> 
      <CurrencyCode>JPY</CurrencyCode> 
      <Amount>580.00</Amount> 
     </Shipping> 
     </Price> 
     <MultipleOffersAtLowestPrice>False</MultipleOffersAtLowestPrice> 
    </LowestOfferListing> 
</LowestOfferListings> 

Я пытаюсь получить количество всех LowestOfferListing элементов, которые имеют ShipsDomestically='False', игнорируя при этом каких-либо ограничений пространства имен.

Это принеси мне подсчет всех предложений:

count(//*[local-name()='LowestOfferListing']) 

Как бы отсеивать тех, с дочерним элементом?

Я попробовал это, но они не работают:

count(//*[local-name()='LowestOfferListing']/descendant::*[not(ShipsDomestically='False')]) 
count(//*[local-name()='LowestOfferListing'][not(ShipsDomestically='False')]) 
count(//*[local-name()='LowestOfferListing'][not(local-name()='ShipsDomestically'='False')]) 
+0

Почему вы игнорируя ограничения пространства имен? Просто обрабатывайте пространства имен правильно. – JLRishe

+0

@JLRishe Это фрагмент ответа MWS. Некоторые ответы используют несколько пространств имен для разных дочерних элементов, что может сделать переносимость для Xpaths между методами несколько сложной. Во многих случаях я обнаружил, что в этом случае просто игнорировать пространства имен. – eComEvo

ответ

0

Это должно работать

count(//*[local-name()='LowestOfferListing' and descendant::ShipsDomestically = 'False']) 
+0

Это работает с небольшой модификацией пространства имен: 'count (// * [local-name() = 'LowestOfferListing' и descendant :: * [local-name() = 'ShipsDomestically'] = 'True'])' – eComEvo