xslt:函数中缺少上下文项

xslt: the context item is absent in Function

我的xml-池就像

<POOL>
  <CUSTOMER>
    <GROUP_ID>
      2
    </GROUP_ID>
  </CUSTOMER>
</POOL>

我有一个函数调用,看起来像

<xsl:value-of select="nck:serviceNo(' ',' ')"/>

我的职能是:

<xsl:function name="nck:serviceNo" as="xs:string">
    <xsl:param name="spacer1" as="xs:string"/>
    <xsl:param name="spacer2" as="xs:string"/>
    <xsl:variable name="num">
      1010<xsl:value-of select="$spacer1" />2020 3030<xsl:value-of select="$spacer2" />
      <xsl:choose>
        <xsl:when test="/POOL/CUSTOMER/GROUP_ID = 2" >
          10
        </xsl:when>
        <xsl:otherwise>
          0
        </xsl:otherwise>
      </xsl:choose> 
    </xsl:variable> 
    <xsl:sequence select="$num"/>
  </xsl:function>

我的错误是:

Type error at char 1 in expression in xsl:when/@test on line 31 column 60 of test.xsl: XPDY0002 Leading '/' selects nothing: the context item is absent Errors were reported during stylesheet compilation

我需要一个解决方法来在函数中提供池,任何人都可以帮忙

添加参数以传入节点,例如<xsl:param name="group-id"/> 并传入例如<xsl:value-of select="nck:serviceNo(' ',' ', /POOL/CUSTOMER/GROUP_ID)"/> 然后你在其中检查 <xsl:when test="$group-id = 2"> 或声明一个全局参数或变量,例如<xsl:param name="main-root" select="/"/> 并使用例如<xsl:when test="$main-root/POOL/CUSTOMER/GROUP_ID = 2">.