title: Axis step child::element cannot be used here: the context item is an atomic value
body: <p>I am not sure why I receive the following error in my XSLT:</p>
  
  <blockquote>
    <p>Axis step child::element(_SetMax42, xs:anyType) cannot be used here:
    the context item is an atomic value</p>
  </blockquote>
  
  <p>It seems like using count on the <code>xsl:when</code> condition seems to cause it, but I don't understand why or how to resolve this to get what I need.</p>
  
  <pre><code>  &lt;xsl:variable name='_LoopVar_102_0_set' select="$_ManageWorkOrderSubmitWorkOrderRequest/soapenv:Envelope[1]/soapenv:Body[1]/bons1:ManageWorkOrderSubmitWorkOrderRequest[1]/WorkOrder[1]/CustomerAccount[1]/ServiceAddress[1]/LineCardInfo[1]/Cable"/&gt;
    &lt;xsl:variable name='_LoopVar_102_1_set' select="$_LoopVar_100_0/Cable"/&gt;
    &lt;xsl:variable name='_SetMax42r'&gt;
      &lt;xsl:choose&gt;
        &lt;xsl:when test="count($_LoopVar_102_0_set) &gt;= count($_LoopVar_102_1_set)"&gt;
          &lt;xsl:apply-templates select="$_LoopVar_102_0_set" mode='enumerate'/&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:when test="count($_LoopVar_102_1_set) &gt;= count($_LoopVar_102_0_set)"&gt;
          &lt;xsl:apply-templates select="$_LoopVar_102_1_set" mode='enumerate'/&gt;
        &lt;/xsl:when&gt;
      &lt;/xsl:choose&gt;
    &lt;/xsl:variable&gt;
    &lt;xsl:variable name='_SetMax42' select="$_SetMax42r/*"/&gt;
    &lt;xsl:variable name='count2'&gt;
      &lt;xsl:choose&gt;
        &lt;xsl:when test='count(_SetMax42) = 0'&gt;
          &lt;xsl:value-of select="1"/&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:otherwise&gt;
          &lt;xsl:value-of select='count(_SetMax42)'/&gt;
        &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
    &lt;/xsl:variable&gt;
    &lt;xsl:for-each select="1 to $count2"&gt;
      &lt;xsl:variable name="_index43" select='$count2'/&gt;
      &lt;xsl:variable name='_LoopVar_102_0' select="$_LoopVar_102_0_set[position()=$_index43]"/&gt;
      &lt;xsl:variable name='_LoopVar_102_1' select="$_LoopVar_102_1_set[position()=$_index43]"/&gt;
  </code></pre>