user3577747
user3577747

Reputation: 1

using xsl:if inside xsl:otherwise i xslt 1.0

Can you please advise is the below xsl tag implementation is correct as I have doubt that the way i am using xsl:if ()inside xsl:otherwise is incorrect we should have use xsl:when for the second condition also..

<xsl:template name="swaption_notional_template_nd_currency">
        <xsl:param name="abcVar"/>
        <xsl:choose>
            <xsl:when test="$ert">              

            </xsl:when>
            <xsl:otherwise>
                <xsl:if test="$abcValue">           

                </xsl:if>
            </xsl:otherwise>
        </xsl:choose>
</xsl:template>

Upvotes: 0

Views: 1498

Answers (2)

Piyush
Piyush

Reputation: 53

You can use <xsl:if> inside the <xsl:otherwise> block below is example 

<xsl:template name="check">
      <xsl:param name="id"/>
      <xsl:choose>
         <xsl:when test="Response/Specification/Section/Item/Property[id=$id]/Boolean1=1">
            <xsl:text>Y</xsl:text>
         </xsl:when>
         <xsl:otherwise>
            <xsl:if test="Response/Specification/Section/Item/Property[id=$id]/Boolean`enter code here`1=0">
                <xsl:text>N</xsl:text>
            </xsl:if>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

Upvotes: 0

Marcus Rickert
Marcus Rickert

Reputation: 4238

Syntactically, it is fine to place <xsl:if></xsl:if> inside a <otherwise></otherwise> block. However, as you already assumed it is a better option (and easier to read) to use another <xsl:when></xsl:when> block.

Your solution may be necessary if your <otherwise></otherwise> block contains portions that are dependant on the tests in your <xsl:choose></xsl:choose> block but independant of the test in your <xsl:if></xsl:if> block, such as:

<xsl:choose>
  <xsl:when test="$ert">              

  </xsl:when>

  <xsl:otherwise>

    <!-- SOMETHING happens here -->

    <xsl:if test="$abcValue">           

    </xsl:if>

    <!-- and/or SOMETHING happens here -->

  </xsl:otherwise>

</xsl:choose>

Upvotes: 1

Related Questions