in reply to XML::LibXML count nodes

Use XPath function count:
my $count = $doc->findvalue("count(//category)");