• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 550
  • Last Modified:

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

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
badtz7229
Asked:
badtz7229
  • 6
  • 4
1 Solution
 
Geert BormansCommented:
<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
 
badtz7229Author Commented:
However,even if I commented that line out, I still get the warning.
0
 
Geert BormansCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
badtz7229Author Commented:
Can you give me an example?
I still don't understand why I can't have a choose inside another choose
0
 
Geert BormansCommented:
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
 
badtz7229Author Commented:
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
 
Geert BormansCommented:
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
 
Geert BormansCommented:
note that I prefer not($Match) over count($Match) = 0
and that I combined the FL1 and FL2
0
 
badtz7229Author Commented:
good idea. thx
0
 
Geert BormansCommented:
welcome
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now