3

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]"/>
kjhughes
  • 106,133
  • 27
  • 181
  • 240
A. Shah
  • 37
  • 6

1 Answers1

2

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.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • If the context item for the code snippet shown is an atomic value, then this is the diagnostic you would expect. (If the context item were a node, then count(_SetMax42) would execute "successfully" and return zero). – Michael Kay Mar 15 '16 at 09:12
  • Ah, you're right. The `$` mistake combined with an atomic context item might be all that's wrong. Thanks. Answer updated. – kjhughes Mar 15 '16 at 14:23
  • Cant believe I missed that. Thanks for the answers. Appreciate it! – A. Shah Mar 15 '16 at 20:50