Counting an elment where its attribut equals to true

Discussion in 'XML' started by khaled Hajjar, Oct 19, 2003.

  1. 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!
    khaled Hajjar, Oct 19, 2003
    #1
    1. Advertising

  2. 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!
    Dimitre Novatchev, Oct 19, 2003
    #2
    1. Advertising

  3. 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!
    khaled Hajjar, Oct 19, 2003
    #3
  4. > 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
    Dimitre Novatchev, Oct 19, 2003
    #4
  5. 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!
    khaled Hajjar, Oct 19, 2003
    #5
  6. 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>
    <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.
    --

    Patrick TJ McPhee
    East York Canada
    Patrick TJ McPhee, Oct 19, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin

    bgsound Elment

    Kevin, Mar 2, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,221
    Ray Booysen
    Mar 2, 2006
  2. Edward A Thompson
    Replies:
    4
    Views:
    529
    Tony Morris
    Feb 11, 2004
  3. hp_

    variable and attribut

    hp_, Sep 13, 2004, in forum: XML
    Replies:
    3
    Views:
    420
  4. Eric
    Replies:
    4
    Views:
    421
    Rolf Magnus
    Aug 18, 2004
  5. bdb112
    Replies:
    45
    Views:
    1,339
    jazbees
    Apr 29, 2009
Loading...

Share This Page