문제

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