Solved

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

Posted on 2012-03-28
10
486 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

 

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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

695 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