Question

Is it possible to count the following TRUE nodes (with different names) with XPath in the XML below?

<my:templateBase>
  <my:executive>true</my:executive>
  <my:seniorManager>false</my:seniorManager>
  <my:manager>false</my:manager>
  <my:supervisor>false</my:supervisor>
  <my:directReport>false</my:directReport>
</my:templateBase>

I can't seem to work out the XPATH, e.g. count(templateBase/*[?=true()]).

Était-ce utile?

La solution

Find all elements which contain the text "true" and count them.

count(//my:templateBase/*[text() = 'true'])

Make sure to correctly register the namespace or use * instead of my as wildcard namespace, for example

count(//*:templateBase/*[text() = 'true'])

I do not know Infopath, maybe it also just omits namespaces.

If you also want to search subnodes for the text "true", use

count(//my:templateBase//*[text() = 'true'])

Autres conseils

The xpath is

count(//my:templateBase/*[. = 'true']

Please be aware that you abviously have some namespace my in your XML. Maybe you have to make your processor aware of this namespaces. You can also use a wildcard, i.e. *:templateBase

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top