2 Replies Latest reply on Nov 27, 2018 7:22 PM by Fofana

    How to apply SUM on values returned by a template function

    Fofana

      I have to loop through unrounded quantities and for each one I call a function getRoundedValue passing the value to round and the rounding policy parameter dynamically

      and summarize all the returned values into one output.

       

      I have somethink like...(reduced code for clarty)

            <xsl:for-each select="//lineItems/usageLineItem/lstLineItems....>

       

                <xsl:variable name="paramToRound">

                <xsl:value-of select="//lineItems/usageLineItem/lstLineItems..../unRoundedQuantity"/>

                </xsl:variable>

       

                <xsl:variable name = "round_policy">

                <xsl:value-of select="../../linteItems/subscriptionAttributes[parameter = 'Rounding_Policy']/value"/>

                </xsl:variable>

       

                <xsl:value-of select="sum(getRoundedValue($paramToRound,$round_policy))"/>

       

            </xsl:for-each>

       

      Can someone help ? Urgent !!!!!

        • 1. Re: How to apply SUM on values returned by a template function
          tsuji

          Before answering the question, I think the construction of the variable paramToRound should be corrected to take into account of the context where the xsl:for-each has established, otherwise, there would be a disparity in identifying the correct 'unRoundedQuantity' element inside the said context.

           

          <xsl:variable name="paramToRound">
              <!--
              <xsl:value-of select="//lineItems/usageLineItem/lstLineItems..../unRoundedQuantity"/>
              -->
              <xsl:value-of select="unRoundedQuantity"/>
          </xsl:variable>
          

           

          Then as to do the sum for the purposing of 'summarizing into one output' - actually not quite sure what actually the summarizing is done concretely - here is how, keeping your two variable written as shown (and corrected ?).

          I have to reference to your other thread to establish some confidence on what getRoundedValue template is and how it is written.

          https://community.oracle.com/thread/4181717

           

          <xsl:for-each select="//lineItems/usageLineItem/lstLineItems....">
          
              <xsl:variable name="paramToRound">
                  <xsl:value-of select="unRoundedQuantity"/>
              </xsl:variable>
          
              <xsl:variable name = "round_policy">
                  <xsl:value-of select="../../linteItems/subscriptionAttributes[parameter = 'Rounding_Policy']/value"/>
              </xsl:variable>
          
              <xsl:variable name="paramRounded">
                  <xsl:call-template name="getRoundedValue">
                      <xsl:with-param name="valueToRound" select="$paramToRound" />
                  </xsl:call-template>
              </xsl:variable>
              
              <xsl:variable name="round_policy_rounded">
                  <xsl:call-template name="getRoundedValue">
                      <xsl:with-param name="valueToRound" select="$round_policy" />
                  </xsl:call-template>
              </xsl:variable>
          
              <xsl:value-of select="number($paramRounded)+number($round_policy_rounded)"/>
          
          </xsl:for-each>
          

           

          Sure, you can combined the related variables such as paramToRound and paramRounded into one without naming explicitly the former.

          number() is added just to make sure, it may not be necessary if the template getRoundedValue is written well.

          • 2. Re: How to apply SUM on values returned by a template function
            Fofana

            Hi, thanks for answering:

            You wrote:

             

            I must precise that we don't round the item called round_policy.

            As the name indicates it's a rule used to round a value. So the getRoundedValue template is just a kind of function that takes 2 parameters:

            - The Value we want to round and

            - The rule to apply which is in Rounding_Policy entry (meaning for example if the value falls inside a certain value ranges we round to a certain value etc...)

             

            This thread is the initial need and I found a workaround to the sum(function()) issue which is not supported by FOP 1.0

            So you are right I should close this present thread.

            Unfortunately, that solution also raises another issue. Please refer to the thread java.lang.StackOverflowError when running bigger XML using FOP1.0

             

            Thanks