count different child elements

Here should go questions about transforming XML with XSLT and FOP.
mariomueller
Posts: 30
Joined: Wed Feb 14, 2018 3:27 pm

count different child elements

Post by mariomueller » Wed Aug 22, 2018 9:26 am

Hi all,

I got a XML like

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<A>
<B1> </B1>
<B1> </B1>
<B2> </B2>
<B2> </B2>
<B3> </B3>
</A>
How can I count the sum of all <B1> and <B2> nodes?

count(count(/A/B1) and count(/A/B2)) --> 1 which is wrong
count(/A/B1 and /A/B2) --> 1 which is wrong

correct would be 4

Thanks
Regards
Mario

Radu
Posts: 6512
Joined: Fri Jul 09, 2004 5:18 pm

Re: count different child elements

Post by Radu » Wed Aug 22, 2018 9:32 am

Hi Mario,

Try this:

Code: Select all

count(/A/B1 | /A/B2)
using "|" you can concat two (or more) node sequences.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

mariomueller
Posts: 30
Joined: Wed Feb 14, 2018 3:27 pm

Re: count different child elements

Post by mariomueller » Wed Aug 22, 2018 9:33 am

Got it:

count(/A/B1 | /A/B2)

mariomueller
Posts: 30
Joined: Wed Feb 14, 2018 3:27 pm

Re: count different child elements

Post by mariomueller » Thu Aug 23, 2018 6:40 am

Hi Radu,

many thanks. As you can see I found the same solution 1 minute later :-)

Regards
Mario

Post Reply