user2352134
user2352134

Reputation: 13

Incorporating certain conditions with in the existing condition in xsl

Let me start first this below question i am asking may be reptetive one but I am stuck up in one thing. I have tried my best and need advise from you guys, please advise.

As below you can see the template I have defined in XSLT 1.0 and there are certain conditions also as shown below:

<xsl:template name="direction_emm_cashflowGDS">
    <xsl:param name="TradeHeaderVar" />
    <xsl:param name="ReturnSwapTradeVar" />
    <xsl:param name="ReturnLegVar" />
    <xsl:param name="InterestLegVar" />
    <xsl:param name="legReferenceVar" />
    <xsl:variable name="cdfPartyRef">
        <xsl:value-of select="$TradeHeaderVar/bookingEntityPerspective" />
    </xsl:variable>

<xsl:choose>
        <xsl:when
            test="($legReferenceVar=$ReturnLegVar/@legIdentifier and 
                   $cdfPartyRef=$ReturnLegVar/payerPartyReference) 
                  or 
                  ($legReferenceVar=$InterestLegVar/@legIdentifier and 
                   $cdfPartyRef=$InterestLegVar/payerPartyReference)">
            <xsl:value-of select="'Pay'" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="'Receive'" />
        </xsl:otherwise>
    </xsl:choose> 
</xsl:template>     

Now as I have organized certain conditions in xsl:when depending upon the specified requirement and now there is a slight change in the requirement.

That is let say:

if $legReferenceVar=$ReturnLegVar/@legIdentifier is not equal then in that case a select of error is need to be displayed.

In other words, if $legReferenceVar != $ReturnLegVar/@legIdentifier then error message to be diasplayed as

<xsl:value-of select="'EEROR'" />

Similiar is the case with another change in requirement is that if $legReferenceVar=$InterestLegVar/@legIdentifier is not equal then a select of error needs to be dispalyed. $legReferenceVar != $InterestLegVar/@legIdentifier then error message to be diasplayed as

 <xsl:value-of select="'EEROR'" />  

Please advise how to incorporate these changes in the existing conditions.

Upvotes: 1

Views: 71

Answers (2)

Mads Hansen
Mads Hansen

Reputation: 66781

xsl:choose can have multiple xsl:when elements:

It consists of a sequence of xsl:when elements followed by an optional xsl:otherwise element. Each xsl:when element has a single attribute, test, which specifies an expression. The content of the xsl:when and xsl:otherwise elements is a template. When an xsl:choose element is processed, each of the xsl:when elements is tested in turn, by evaluating the expression and converting the resulting object to a boolean as if by a call to the boolean function. The content of the first, and only the first, xsl:when element whose test is true is instantiated. If no xsl:when is true, the content of the xsl:otherwise element is instantiated. If no xsl:when element is true, and no xsl:otherwise element is present, nothing is created.

Simply add your new ERROR condition as another xsl:when criteria:

<xsl:template name="direction_emm_cashflowGDS">
    <xsl:param name="TradeHeaderVar" />
    <xsl:param name="ReturnSwapTradeVar" />
    <xsl:param name="ReturnLegVar" />
    <xsl:param name="InterestLegVar" />
    <xsl:param name="legReferenceVar" />
    <xsl:variable name="cdfPartyRef">
        <xsl:value-of select="$TradeHeaderVar/bookingEntityPerspective" />
    </xsl:variable>

    <xsl:choose>
        <xsl:when test="$legReferenceVar != $ReturnLegVar/@legIdentifier
                        or $legReferenceVar != $InterestLegVar/@legIdentifier">
            <xsl:value-of select="'ERROR'"/>
        </xsl:when>
        <xsl:when
            test="($legReferenceVar=$ReturnLegVar/@legIdentifier 
                   and $cdfPartyRef=$ReturnLegVar/payerPartyReference) 
                 or 
                  ($legReferenceVar=$InterestLegVar/@legIdentifier 
                   and $cdfPartyRef=$InterestLegVar/payerPartyReference)">
            <xsl:value-of select="'Pay'" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="'Receive'" />
        </xsl:otherwise>
    </xsl:choose> 
</xsl:template>  

Upvotes: 1

LarsH
LarsH

Reputation: 28004

Just add a <xsl:when> clause with your new condition, as a new child of <xsl:choose>:

<xsl:choose>
   <xsl:when test="$legReferenceVar != $ReturnLegVar/@legIdentifier">
      <xsl:text>ERROR</xsl:text>
   </xsl:when>
   ...etc.

Upvotes: 1

Related Questions