Axis step child::element cannot be used here: the context item is an atomic value

I am not sure why I receive the following error in my XSLT:

Axis step child::element(_SetMax42, xs:anyType) cannot be used here: the context item is an atomic value

It seems like using count on the xsl:when condition seems to cause it, but I don't understand why or how to resolve this to get what I need.

  <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"/>
  <xsl:variable name='_LoopVar_102_1_set' select="$_LoopVar_100_0/Cable"/>
  <xsl:variable name='_SetMax42r'>
    <xsl:choose>
      <xsl:when test="count($_LoopVar_102_0_set) >= count($_LoopVar_102_1_set)">
        <xsl:apply-templates select="$_LoopVar_102_0_set" mode='enumerate'/>
      </xsl:when>
      <xsl:when test="count($_LoopVar_102_1_set) >= count($_LoopVar_102_0_set)">
        <xsl:apply-templates select="$_LoopVar_102_1_set" mode='enumerate'/>
      </xsl:when>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name='_SetMax42' select="$_SetMax42r/*"/>
  <xsl:variable name='count2'>
    <xsl:choose>
      <xsl:when test='count(_SetMax42) = 0'>
        <xsl:value-of select="1"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select='count(_SetMax42)'/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:for-each select="1 to $count2">
    <xsl:variable name="_index43" select='$count2'/>
    <xsl:variable name='_LoopVar_102_0' select="$_LoopVar_102_0_set[position()=$_index43]"/>
    <xsl:variable name='_LoopVar_102_1' select="$_LoopVar_102_1_set[position()=$_index43]"/>

Answers


Instead of

count(_SetMax42)

use

count($_SetMax42)

...although you probably have another similar sort of mistake elsewhere as this alone doesn't fully account for your error message.


Update: As pointed out by Michael Kay in the comments, if the context item is an atomic value at this point, making the above fix alone may be sufficient. Without the $, _SetMax42 would be considered to be a child element of the context item, and count() would return 0 if the context item were a node but fail with the given error message if it were an atomic value. With the $, $_setMax42 wouldn't depend upon the context item and adding $ may alone resolve your problem.


Need Your Help

Query in a loop which is executed only once Java

java sql swing for-loop jdbc

I am currently working on a Java project (on NetBeans) and I am struggling with a problem.

Jquery dynamic buttons dialog for in loop doesn't populate function

javascript jquery loops dialog

I am creating dynamic buttons for a jQuery dialog. A json object contains the info for the buttons. I am using a for in loop to loop through each property in the object. The anonymous function that...