Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xpath to check multiple empty children

With the following xml, I'm trying to return true or false depending on whether all <CrucialNumber> elements are empty or not:

<Invoice>
  <Details>
    <LIN1>
      <Quantity>1</Quantity>
      <Product>Test XML</Product>
      <CrucialNumber/>
    </LIN1>
    <LIN1>
      <Quantity>1</Quantity>
      <Product>Test XML</Product>
      <CrucialNumber/>
    </LIN1>
    <LIN1>
      <Quantity>1</Quantity>
      <Product>Test XML</Product>
      <CrucialNumber>123456</CrucialNumber>
    </LIN1>
  </Details>
</Invoice>

The data-type of the CrucialNumber element is string.

So far, these are the xpath expressions I have tried:

string-length(//CrucialNumber/*) > 0;    

not(//CrucialNumber/*[text()]);

./Details/LIN1[*]/CrucialNumber[1] = "";
like image 541
Vincent Avatar asked Dec 15 '25 19:12

Vincent


1 Answers

not(.//CrucialNumber/node())

should do it, it will be true if and only if either (a) there are no CrucialNumber descendant elements at all, or (b) all the descendant CrucialNumber elements are empty.

like image 56
Ian Roberts Avatar answered Dec 19 '25 07:12

Ian Roberts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!