if conditions

Discussion in 'XML' started by Eliza Zadura, Sep 17, 2003.

  1. Eliza Zadura

    Eliza Zadura Guest

    I have the following loops:

    <xsl:for-each
    select="//node[@type='N_MICROFLOW_SD'][@display=$microflow_id]">
    <xsl:variable name="sd_id" select="./@object"/>
    <xsl:variable name="doc_id"
    select="//link[@type='L_DC_SD'][@to=$sd_id]/@from"/>

    <xsl:if test="//link[@type='L_MICROFLOW_WA_SD'][@to=$sd_id]/@from!=''">
    <tr>
    <td>Output:</td>
    <td>
    <xsl:value-of select="//object[@id=$sd_id]/property[@name='SDMSGNAM']"/>
    <xsl:text> - </xsl:text>
    <xsl:value-of select="//object[@id=$doc_id]/property[@name='ACNAME']"/>
    </td>
    </tr>
    </xsl:if>

    </xsl:for-each>

    <xsl:for-each
    select="//node[@type='N_MICROFLOW_SD'][@display=$microflow_id]">
    <xsl:variable name="sd_id" select="./@object"/>
    <xsl:variable name="doc_id"
    select="//link[@type='L_DC_SD'][@to=$sd_id]/@from"/>

    <xsl:if test="//link[@type='L_WC_SD'][@to=$sd_id]/@from!=''">
    <tr>
    <td>Output:</td>
    <td>
    <xsl:value-of select="//object[@id=$sd_id]/property[@name='SDMSGNAM']"/>
    <xsl:text> - </xsl:text>
    <xsl:value-of select="//object[@id=$doc_id]/property[@name='ACNAME']"/>
    </td>
    </tr>
    </xsl:if>

    </xsl:for-each>

    The only difference between them is that the first one checks one type
    of <link> element (row 7), and the other another type (row 26). Can I do
    this with one loop and one if-condition? Basically, is there an or? I
    sure can't seem to find a way, but then again it is late in the
    afternoon and I'm tired...

    -----------------
    Eliza Zadura
    Trainee-Developer

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Eliza Zadura, Sep 17, 2003
    #1
    1. Advertising

  2. Eliza Zadura

    Martin Boehm Guest

    "Eliza Zadura" <> wrote in message
    news:3f6879cb$0$62079$

    > I have the following loops:
    >
    > [...snip...]
    >
    > The only difference between them is that the first one checks one type
    > of <link> element (row 7), and the other another type (row 26). Can I
    > do this with one loop and one if-condition? Basically, is there an
    > or?


    There is no "else", but a kind of "switch":

    ---XSL Fragment---------------------------------------------------------
    <xsl:choose>
    <xsl:when
    test="//link[@type='L_MICROFLOW_WA_SD'][@to=$sd_id]/@from!=''">
    <!-- do one thing -->
    </xsl:when>
    <xsl:when test="//link[@type='L_WC_SD'][@to=$sd_id]/@from!=''">
    <!-- do some other thing -->
    </xsl:when>
    <xsl:eek:therwise>
    <!-- do something completely different-->
    </xsl:eek:therwise>
    </xsl:choose>
    ------------------------------------------------------------------------

    HTH

    martin
     
    Martin Boehm, Sep 17, 2003
    #2
    1. Advertising

  3. Eliza Zadura

    Eliza Zadura Guest

    Thanks Martin. That doesn't quite do the trick though. What I'm looking
    for is a construct that will allow me to do the following (in
    pseudocode):

    If the link of TYPE or TYPE where the attribute TO is ID exists then

    do something.

    The crux is that if both exist, I want it done only once.

    For - if - break I suppose. Can this be done with xsl?

    -----------------
    Eliza Zadura
    Trainee-Developer

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Eliza Zadura, Sep 18, 2003
    #3
  4. Eliza Zadura

    Martin Boehm Guest

    "Eliza Zadura" <> wrote in message
    news:3f6961cc$0$62081$

    > Thanks Martin. That doesn't quite do the trick though. What I'm
    > looking for is a construct that will allow me to do the following (in
    > pseudocode):
    >
    > If the link of TYPE or TYPE where the attribute TO is ID exists then
    > do something.


    OIC. Maybe you should post a XML fragment to work with. Because your
    select="//....." is very unspecific it quite difficult to picture your
    XML structure.

    It could solve your problem to select the nodes in question with
    someting like
    select="//link[@type='TYPE_1' or @type='TYPE_2']"
    and use "position() = 1" to test for the first node in the resulting
    node-set.
    If this set has two nodes or more, e.g. both types exist, the <!-- do
    something --> part is nevertheless executed only once.

    Martin
     
    Martin Boehm, Sep 18, 2003
    #4
  5. Eliza Zadura

    Eliza Zadura Guest

    Yes, that does it! :eek:)

    Thanks again.

    -----------------
    Eliza Zadura
    Trainee-Developer

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Eliza Zadura, Sep 18, 2003
    #5
    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. Weng Tianxiang
    Replies:
    7
    Views:
    1,110
    Mike Treseler
    Nov 25, 2003
  2. The Weiss Family

    race conditions/pulse width

    The Weiss Family, Oct 16, 2004, in forum: VHDL
    Replies:
    6
    Views:
    723
    Jim Lewis
    Oct 19, 2004
  3. Taras_96
    Replies:
    7
    Views:
    6,677
    Taras_96
    Apr 5, 2005
  4. Jawor

    Launch conditions

    Jawor, May 6, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    394
    Jawor
    May 6, 2004
  5. ime
    Replies:
    4
    Views:
    4,919
    IPGrunt
    Jan 26, 2005
Loading...

Share This Page