Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Counting an elment where its attribut equals to true

Reply
Thread Tools

Counting an elment where its attribut equals to true

 
 
khaled Hajjar
Guest
Posts: n/a
 
      10-19-2003
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.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Dimitre Novatchev
Guest
Posts: n/a
 
      10-19-2003
So what is your question?

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL



"khaled Hajjar" <> wrote in message
news:3f9213a8$0$195$...
> 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.
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
 
 
 
khaled Hajjar
Guest
Posts: n/a
 
      10-19-2003


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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Dimitre Novatchev
Guest
Posts: n/a
 
      10-19-2003
> In other way, How can I know in my poste elements that I have at least
> one element its attribut equal to true?


The condition to test for is:

/root/categorie/poste[@att = 'true']


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


 
Reply With Quote
 
khaled Hajjar
Guest
Posts: n/a
 
      10-19-2003
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Patrick TJ McPhee
Guest
Posts: n/a
 
      10-19-2003
In article <3f92c109$0$196$>,
khaled Hajjar <> wrote:

% 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>
<xsltherwise>There is no poste with att set to 'true'.</xsltherwise>
</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.
--

Patrick TJ McPhee
East York Canada

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[False,True] and [True,True] --> [True, True]????? bdb112 Python 45 04-29-2009 02:35 AM
bgsound Elment Kevin ASP .Net 1 03-02-2006 01:28 PM
variable and attribut hp_ XML 3 09-14-2004 06:43 AM
pointer to an elment in a stl vector Eric C++ 4 08-18-2004 10:05 PM
does String.equals breaks the equals contract? Edward A Thompson Java 4 02-11-2004 11:33 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57