轴步骤子项::元素不能在此处使用:上下文项是原子值



我不确定为什么在我的 XSLT 中收到以下错误:

轴步骤子项::元素(_SetMax42,xs:anyType)不能在此处使用: 上下文项是原子值

似乎在xsl:when条件下使用计数似乎是导致它的,但我不明白为什么或如何解决这个问题以获得我需要的东西。

  <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]"/>

而不是

count(_SetMax42)

count($_SetMax42)

。尽管您可能在其他地方有另一种类似的错误,因为仅此一项并不能完全解释您的错误消息。


更新:正如Michael Kay在评论中指出的那样,如果此时上下文项是原子值,则仅进行上述修复可能就足够了。 如果没有$_SetMax42将被视为上下文项的子元素,如果上下文项是节点,则count()将返回 0,但如果它是原子值,则返回给定错误消息失败。 使用$$_setMax42将不依赖于上下文项,添加$可能单独解决您的问题。

最新更新