Number of xml elements with multiple conditions

I have the following XML code that I am trying to convert using xlst:

<setting> <type>house</type> <context>roof</context> <value>blue</value> </setting> <setting> <type>house</type> <context>kitchen</context> <value>red</value> </setting> <setting> <type>house</type> <context>floor</context> <value>black</value> </setting> <setting> <type>apartment</type> <context>roof</context> <value>red</value> </setting> 

I want to calculate if the setting-> type "flat" has "context-> gender".

I tried to do this with

 <xsl:if test="count(setting[type='apartment'] and setting[context='floor']) &lt; 1"> <!-- do what ever !--> </xsl:if> 

but it does not seem to work. Am I getting an exception due to trying to turn a number into a boolean? Any suggestions?

update: I realized that I can use:

 <xsl:if test="count(setting[type='apartment' and context='floor']) &lt; 1"> 
+4
source share
2 answers

The statement inside count returns a boolean that is incorrect. count () requires node-set to be able to count nodes. If this is the same setting item that should have type and apartment elements with the required values, you are probably looking at:

 count(setting[type='apartment' and context='floor']) &lt; 1 

Otherwise, if you need a sum of settings that have type = flat or context = gender (excluding the counting parameter, which has both elements with the required values), you will probably need:

 count(setting[type='apartment'] | setting[context='floor']) &lt; 1 
+2
source

How about using cascading predicates like ??

 count(setting[type='apartment'][context='floor']) &lt; 1 
0
source

Source: https://habr.com/ru/post/1395322/


All Articles