Solved

Error: xsl:choose cannot be a child of the 'xls:choose' element

Posted on 2012-03-28
10
458 Views
Last Modified: 2012-03-29
Why am i unable to place a choose within another choose, when the code already allowed me to do before?
What would be a workaround then?

<xsl:variable name="tempVar">
      <xsl:choose>
            <xsl:when test="count($Match) = 0">
                  <xsl:choose>
                        <xsl:when test="contains($FAILED,DI/OU)">N</xsl:when>

                                <xsl:choose>  <!-- ERROR: xsl:choose cannot be a child of the 'xls:choose' element -->
                                <xsl:when test="count($MatchFL1) > 0">RE</xsl:when>
                                    <xsl:otherwise>
                                    <xsl:when test="count($MatchFL2) > 0">RE</xsl:when>
                                    </xsl:otherwise>
                                </xsl:choose>
                                       
                        <xsl:otherwise>Y</xsl:otherwise>
                  </xsl:choose>
            </xsl:when>
            <xsl:when test="contains($FAILED,DI/OU)">
                  <xsl:choose>
                        <xsl:when test="contains($FAILED,$Match/Code)">N</xsl:when>
                        <xsl:otherwise>Y</xsl:otherwise>
                  </xsl:choose>
            </xsl:when>

            <xsl:when test="$tmp = 'ETE' or $off = 'ETA'">N</xsl:when>

        <xsl:otherwise>Y</xsl:otherwise>
      </xsl:choose>
</xsl:variable>
0
Comment
Question by:badtz7229
  • 6
  • 4
10 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37778904
<xsl:when test="contains($FAILED,DI/OU)">N</xsl:when>
note that you already closed the xsl:when
which means the choose is a sibling to xsl:when, not a child
0
 

Author Comment

by:badtz7229
ID: 37778946
However,even if I commented that line out, I still get the warning.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37778965
what I mean is:
you need to wrap the choose inside the when.
Right now your choose is a direct child of another choose.
That si not allowed.
only when and otherwise can be children of a choose
so if you need a choose inside a choose, the inner choose needs to be a child of either a when branche or an otherwise branch

you have
choose
---when
---choose
------when

where you need
choose
---when
------choose
---------when

does that make sense?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:badtz7229
ID: 37779009
Can you give me an example?
I still don't understand why I can't have a choose inside another choose
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37779054
well, a choose has by definition a series of when branches and zero or one otherwise
the exectution of a choose works as follows
only execute the first when clause that has a @test that evaluates to true, and if none evaluate to true, execute the otherwise branch (if there is one)

If you want to have a choose inside a choose, you need to have it inside one of the when branches. Outside it makes no sense.

What exactly do you want to achieve?
0
 

Author Comment

by:badtz7229
ID: 37781940
i guess the only way i can make my code work is to do the following:

so if count >0 then choose either one of the cases below.

           <xsl:when test="count($Match) = 0">
                  <xsl:choose>
                        <xsl:when test="contains($FAILED,DI/OU)">N</xsl:when>
                         <xsl:when test="count($MatchFL1) > 0">RE</xsl:when>
                         <xsl:when test="count($MatchFL2) > 0">RE</xsl:when>
                              ........
thx anyway
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 37782031
well, I still don't understand how you want to conceptually have a choose directly inside a choose, since the inner choose is not an alternative branche on its own

A choose needs to have a series of alternative branches. If you want to have a new condition inside one of the branches, you can do

or you can be more precise in the original statements

I would rewrite your piece of code above like this
<xsl:choose>
        <xsl:when test="not($Match) and contains($FAILED,DI/OU)">N</xsl:when>
        <xsl:when test="not($Match) and ($MatchFL1 | $MatchFL2)">RE</xsl:when>
                              ........

Open in new window

0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37782039
note that I prefer not($Match) over count($Match) = 0
and that I combined the FL1 and FL2
0
 

Author Closing Comment

by:badtz7229
ID: 37783884
good idea. thx
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37783894
welcome
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question