Solved

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

Posted on 2012-03-28
10
438 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now