none
Issue with xslt RRS feed

  • Question

  • Hi All,

    <xsl:choose>

    1.<xsl:when test="number(DISCOUNT_RATE1) lt number(DISCOUNT_RATE2)">UP</xsl:when>
    2.<xsl:when test="number(DISCOUNT_RATE2) lt number(DISCOUNT_RATE1)">DOWN</xsl:when>
    3.<xsl:when test="number(DISCOUNT_RATE2) eq number(DISCOUNT_RATE1)">SAME</xsl:when>
    <xsl:otherwise>

    <xsl:value-of select="NULL"/>

    </xsl:otherwise>

    </xsl:choose>


    for 3rd command it should not compare ZERO , means (0=0) should not be considered rather zero should be replace with a variable (number/ character) like ('A'='B') /(1=2) then the condition is moved to NULL highlighted in blue.
    Thanks in advance.


    • Edited by BizTalk1234 Thursday, November 19, 2015 6:57 AM
    Thursday, November 19, 2015 6:55 AM

Answers

  • Hi,

    Try this.

      <xsl:template name="DISCOUNT_RATE">
        <xsl:param name="DISCOUNT_RATE1"/>
        <xsl:param name="DISCOUNT_RATE2"/>
        <xsl:choose>
          <xsl:when test="number($DISCOUNT_RATE1) = 0 and number($DISCOUNT_RATE2) = 0">
            <xsl:text>ZERO</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:choose>
              <xsl:when test="number($DISCOUNT_RATE1) &lt; number($DISCOUNT_RATE2)">
                <xsl:text>UP</xsl:text>
              </xsl:when>
              <xsl:when test="number($DISCOUNT_RATE2) &lt; number($DISCOUNT_RATE1)">
                <xsl:text>DOWN</xsl:text>
              </xsl:when>
              <xsl:when test="number($DISCOUNT_RATE1) = number($DISCOUNT_RATE2)">
                <xsl:text>SAME</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="NULL"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:template>

    Test:

      <xsl:template match="/">
        <Test>
          <TC1>
            <!--Test 0=0 case-->
            <TC_Input>
              <DISCOUNT_RATE1>0</DISCOUNT_RATE1>
              <DISCOUNT_RATE2>0</DISCOUNT_RATE2>
            </TC_Input>
            <TC_Output>
              <xsl:call-template name="DISCOUNT_RATE">
                <xsl:with-param name="DISCOUNT_RATE1" select="'0'"/>
                <xsl:with-param name="DISCOUNT_RATE2" select="'0'"/>
              </xsl:call-template>
            </TC_Output>
          </TC1>
          <TC2>
            <!--Test rate1 less then rate2-->
            <TC_Input>
              <DISCOUNT_RATE1>4</DISCOUNT_RATE1>
              <DISCOUNT_RATE2>8</DISCOUNT_RATE2>
            </TC_Input>
            <TC_Output>
              <xsl:call-template name="DISCOUNT_RATE">
                <xsl:with-param name="DISCOUNT_RATE1" select="'4'"/>
                <xsl:with-param name="DISCOUNT_RATE2" select="'8'"/>
              </xsl:call-template>
            </TC_Output>
          </TC2>
          <TC3>
            <!--Test rate2 less then rate1-->
            <TC_Input>
              <DISCOUNT_RATE1>8</DISCOUNT_RATE1>
              <DISCOUNT_RATE2>4</DISCOUNT_RATE2>
            </TC_Input>
            <TC_Output>
              <xsl:call-template name="DISCOUNT_RATE">
                <xsl:with-param name="DISCOUNT_RATE1" select="'8'"/>
                <xsl:with-param name="DISCOUNT_RATE2" select="'4'"/>
              </xsl:call-template>
            </TC_Output>
          </TC3>
          <TC4>
            <!--Test rate1 equl rate2, but not 0-->
            <TC_Input>
              <DISCOUNT_RATE1>4</DISCOUNT_RATE1>
              <DISCOUNT_RATE2>4</DISCOUNT_RATE2>
            </TC_Input>
            <TC_Output>
              <xsl:call-template name="DISCOUNT_RATE">
                <xsl:with-param name="DISCOUNT_RATE1" select="'4'"/>
                <xsl:with-param name="DISCOUNT_RATE2" select="'4'"/>
              </xsl:call-template>
            </TC_Output>
          </TC4>
        </Test>
      </xsl:template>

    Best regards

    Rasmus Jaeger

    • Marked as answer by BizTalk1234 Monday, November 30, 2015 4:47 PM
    Monday, November 30, 2015 12:00 PM

All replies

  • Hi Ram,

    Thank you for posting in MSDN forum.

    I am not getting your question properly, sorry for that. Could you please explain us what you want to achieve with xslt?


    Thanks,

    If my reply is helpful please mark as Answer or vote as Helpful.

    My blog | Twitter | LinkedIn

    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

    Thursday, November 19, 2015 10:34 AM
    Moderator
  • So, xsl:choose is short-circuited so if 0=0 is a special case, you need to put that before your current case #3.
    Thursday, November 19, 2015 12:08 PM
    Moderator
  • Hi,

    Try this.

      <xsl:template name="DISCOUNT_RATE">
        <xsl:param name="DISCOUNT_RATE1"/>
        <xsl:param name="DISCOUNT_RATE2"/>
        <xsl:choose>
          <xsl:when test="number($DISCOUNT_RATE1) = 0 and number($DISCOUNT_RATE2) = 0">
            <xsl:text>ZERO</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:choose>
              <xsl:when test="number($DISCOUNT_RATE1) &lt; number($DISCOUNT_RATE2)">
                <xsl:text>UP</xsl:text>
              </xsl:when>
              <xsl:when test="number($DISCOUNT_RATE2) &lt; number($DISCOUNT_RATE1)">
                <xsl:text>DOWN</xsl:text>
              </xsl:when>
              <xsl:when test="number($DISCOUNT_RATE1) = number($DISCOUNT_RATE2)">
                <xsl:text>SAME</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="NULL"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:template>

    Test:

      <xsl:template match="/">
        <Test>
          <TC1>
            <!--Test 0=0 case-->
            <TC_Input>
              <DISCOUNT_RATE1>0</DISCOUNT_RATE1>
              <DISCOUNT_RATE2>0</DISCOUNT_RATE2>
            </TC_Input>
            <TC_Output>
              <xsl:call-template name="DISCOUNT_RATE">
                <xsl:with-param name="DISCOUNT_RATE1" select="'0'"/>
                <xsl:with-param name="DISCOUNT_RATE2" select="'0'"/>
              </xsl:call-template>
            </TC_Output>
          </TC1>
          <TC2>
            <!--Test rate1 less then rate2-->
            <TC_Input>
              <DISCOUNT_RATE1>4</DISCOUNT_RATE1>
              <DISCOUNT_RATE2>8</DISCOUNT_RATE2>
            </TC_Input>
            <TC_Output>
              <xsl:call-template name="DISCOUNT_RATE">
                <xsl:with-param name="DISCOUNT_RATE1" select="'4'"/>
                <xsl:with-param name="DISCOUNT_RATE2" select="'8'"/>
              </xsl:call-template>
            </TC_Output>
          </TC2>
          <TC3>
            <!--Test rate2 less then rate1-->
            <TC_Input>
              <DISCOUNT_RATE1>8</DISCOUNT_RATE1>
              <DISCOUNT_RATE2>4</DISCOUNT_RATE2>
            </TC_Input>
            <TC_Output>
              <xsl:call-template name="DISCOUNT_RATE">
                <xsl:with-param name="DISCOUNT_RATE1" select="'8'"/>
                <xsl:with-param name="DISCOUNT_RATE2" select="'4'"/>
              </xsl:call-template>
            </TC_Output>
          </TC3>
          <TC4>
            <!--Test rate1 equl rate2, but not 0-->
            <TC_Input>
              <DISCOUNT_RATE1>4</DISCOUNT_RATE1>
              <DISCOUNT_RATE2>4</DISCOUNT_RATE2>
            </TC_Input>
            <TC_Output>
              <xsl:call-template name="DISCOUNT_RATE">
                <xsl:with-param name="DISCOUNT_RATE1" select="'4'"/>
                <xsl:with-param name="DISCOUNT_RATE2" select="'4'"/>
              </xsl:call-template>
            </TC_Output>
          </TC4>
        </Test>
      </xsl:template>

    Best regards

    Rasmus Jaeger

    • Marked as answer by BizTalk1234 Monday, November 30, 2015 4:47 PM
    Monday, November 30, 2015 12:00 PM