Counting an elment where its attribut equals to true

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • khaled Hajjar

    Counting an elment where its attribut equals to true

    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

    #2
    Re: Counting an elment where its attribut equals to true

    So what is your question?

    =====
    Cheers,

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



    "khaled Hajjar" <elhajjar@look. ca> wrote in message
    news:3f9213a8$0 $195$75868355@n ews.frii.net...[color=blue]
    > 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![/color]


    Comment

    • khaled Hajjar

      #3
      Re: Counting an elment where its attribut equals to true



      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!

      Comment

      • Dimitre Novatchev

        #4
        Re: Counting an elment where its attribut equals to true

        > In other way, How can I know in my poste elements that I have at least[color=blue]
        > one element its attribut equal to true?[/color]

        The condition to test for is:

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


        =====
        Cheers,

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


        Comment

        • khaled Hajjar

          #5
          Re: Counting an elment where its attribut equals to true

          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!

          Comment

          • Patrick TJ McPhee

            #6
            Re: Counting an elment where its attribut equals to true

            In article <3f92c109$0$196 $75868355@news. frii.net>,
            khaled Hajjar <elhajjar@look. ca> 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:otherwise> There is no poste with att set to 'true'.</xsl:otherwise>
            </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
            ptjm@interlog.c om

            Comment

            Working...