Counting an elment where its attribut equals to true

K

khaled Hajjar

Hello,

I have this template :
<root>
<categorie>
<poste att = 'true'>
.....
</poste>
<poste att = 'false'>
.....
</poste>
<poste att = 'true'>
.....
</poste>
</categorie>
<categorie>
................
...............
</categorie>
</root>

In my XSL, I like to check if all poste's attribut equal to false, I
will output a text message "there is no poste"
else output the poste where attribut equal to true.

Thanks for your support.
 
K

khaled Hajjar

In my XSL, what do I put to have these in the output file? :

If all poste's attribut equal to false, will output a text message
"there is no poste"
else output value element of poste, where attribut equal to true.

In other way, How can I know in my poste elements that I have at least
one element its attribut equal to true?

Thanks
 
K

khaled Hajjar

Thanks for your answer, but it still some thing missing.
Sorry about my english.

These way, it works element by element, but I need before I parsed all
poste elements, I like to know if there is a poste element have an
attribut 'true'.

If the attribut of all poste elments are false, I will output the
message 'there no poste'

I will give an example :
<categorie>
<poste att='true'>
comments about poste a
</poste>
<poste att='false'>
comments about poste b
</poste>
<poste att='false'>
comments about poste c
</poste>
</categorie>

If I use this test, I will get 'comments about poste a'. This is a
correct, but my question, if I set the first attribut to false, I want
the output is 'there no poste' one time for the 3 poste element.

Another, I like to have a condition before start parsing the poste
elements, that tell me in these all poste element, there is at least one
attribut to true.

Thanks
 
P

Patrick TJ McPhee

% These way, it works element by element, but I need before I parsed all
% poste elements, I like to know if there is a poste element have an
% attribut 'true'.

You need to use a conditional test.
<xsl:choose>
<xsl:when test='/categorie/poste[@att = "true"]'>
<xsl:value-of select='/categorie/poste[@att = "true"]'/>
</xsl:when>
<xsl:eek:therwise>There is no poste with att set to 'true'.</xsl:eek:therwise>
</xsl:choose>

If you need to handle cases where more than one poste has att set to
true differently, you could have

<xsl:apply-templates match='/categorie/poste[@att = "true"]'/>

instead of using xsl:value-of. If it's too slow, you could put
the select expression in a variable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top