'select and count nested elements with regex expression

I have an XML file like this:

<apps>
    <mobile-app>
    </mobile-app>
    <mobile-app>
    </mobile-app>
    <web-app>
    </web-app>
    <xpto>
    </xpto>
</apps>

and I want to count how many *-apps I have in it, something like count(//apps/"<(.*)-app>").

Already tried to search here but it is difficult as many questions have the xpath expression related with functions of some programming language, which is something I want to avoid here.



Solution 1:[1]

In XPath 2.0 or later to solve that with regular expression matching you could use count(apps/*[matches(local-name(), '-app$')]). However, the check that the end of the name is -app it would suffice to use ends-with(local-name(), '-app').

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martin Honnen