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()]).

有帮助吗?

解决方案

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'])

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top