使用选择何时使用参数为应用模板调用 XSLT 设置条件

Using a choose when to make conditional with param for apply templates call XSLT

我处于需要根据特定条件发送参数的情况。我尝试在 apply templates 元素中使用 choose-when 元素,但这是不允许的。

带有参数的应用模板元素:

<xsl:apply-templates select="Header/Amounts/Totals/TotalLineAmount[string(text())]" mode="MOALoop">
    <xsl:with-param name="qualifier" select="'203'">

这是我的选择:

<xsl:choose>
            <xsl:when test="imdQualifier != ''">
              <xsl:value-of select="$imdQualifier"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="$qualifier"/>
            </xsl:otherwise>
          </xsl:choose>

如果imdQualifier != '',那么参数应该是$imdQualifier,否则应该是203。

如何在应用模板元素中实现此逻辑?

也许你的意思是这样做...

<xsl:apply-templates select="Header/Amounts/Totals/TotalLineAmount[string(text())]" mode="MOALoop">
   <xsl:with-param name="qualifier">
      <xsl:choose>
        <xsl:when test="imdQualifier != ''">
          <xsl:value-of select="$imdQualifier"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="'203'"/>
        </xsl:otherwise>
      </xsl:choose>
   </xsl:with-param>
</xsl:apply-templates>