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.
CodePudding user response:
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')
.