4 Replies Latest reply: Mar 4, 2013 9:26 AM by Dr.Thrax RSS

    How can I use an IF ELSE statement and the xdoxslt: get_variable together?

    Dr.Thrax
      First of all, I'm a big fan of this forum and I just want to thank the community for helping make the BI Publisher world a better place.

      I'm trying to populate a table with a years worth of data with the column=PRODUCT and row=month of DATE. Here's the catch, not all of the months will have data. So here's where my problem is, I'm not able to use an IF ELSE statement along with a XDOXSLT:GET_VARIABLE expression so that if there's no data for that month the default value will be 0.

      Can someone help me find a solution to either one of the attempts below or a completely new method? Thanks!

      BP4 = numeric month value using DATE (more code to pull only month from DATE not included here)
      JAN1 = PRICE if data exists, else 0

      1) I tried this and it didn't work:
      <?if: xdoxslt:get_variable($_XDOCTX,'BP4'),01 then xdoxslt:set_variable($_XDOCTX, 'JAN1',PRICE) else xdoxslt:set_variable($_XDOCTX, 'JAN1',0) end if?>
      <?xdoxslt:get_variable($_XDOCTX,'JAN1')?>
      <?end if?>

      2) I tried this and it didn't work:
      <?xdoxslt:ifelse(xdoxslt:get_variable($_XDOCTX,'BP4')='01',xdoxslt:set_variable($_XDOCTX, 'JAN1',PRICE),xdoxslt:set_variable($_XDOCTX, 'JAN1',0))?>
      <?xdoxslt:get_variable($_XDOCTX,'JAN1')?>
      <?end if?>

      3) I tried this and it didn't work:
      <?xdofx:if xdoxslt:get_variable($_XDOCTX,'BP4')='01' then xdoxslt:set_variable($_XDOCTX, 'JAN1',PRICE) else xdoxslt:set_variable($_XDOCTX, 'JAN1',0) end if?>
      <?xdoxslt:get_variable($_XDOCTX,'JAN1')?>
      <?end if?>

      sample XML:
      <ROW>
      <Name>Craig Hernandez</NAME>
      <DATE>2013-01-01T00:00:00.000+08:00</DATE>
      <PRICE>31</PRICE>
      <PRODUCT>BPD</PRODUCT>
      </ROW>


      -DrT

      Edited by: 990965 on Feb 28, 2013 8:27 AM
        • 1. Re: How can I use an IF ELSE statement and the xdoxslt: get_variable together?
          Avinash_Varma
          so u have to just check price is null or not . if null u want 0 as value ??

          u can try this na why u were using variable ..

          <?xdoxslt:ifelse(PRICE!='',PRICE,0)?>

          i may be wrong but just trying to understand your issue. you can use get variable with ifelse statement.

          can you send me your template and xml . i will try once

          email:datlaavinash@gmail.com
          • 2. Re: How can I use an IF ELSE statement and the xdoxslt: get_variable together?
            Dr.Thrax
            let me clarify my logic, the template 1) searches for the relevant PRODUCT (in the case below, it searches for BPD which is the column in the table) 2) searches for the relevant month in DATE (which is the row in the table) 3) if data exists, get PRICE else default to 0

            Variable definitions:
            BP4 = numeric month value from DATE (more code to get this value not included here, but it works...)
            JAN1 = set to PRICE if data exists for that month, else 0

            the query is only pulling all of the existing data, so if there's no data for March then there wouldn't be a March entry in the xml. In the sample xml below, we only have data for the first two months (Jan, Feb) so that's the only data in the xml. I can't check if PRICE is null because the xml will not have any data for March.

            I've read through other threads and it seems that BI Publisher can't use an IF THEN ELSE with the XDOXSLT:GET_VARIABLE. I sent the template and xml to you.


            Sample XML:
            <ROW>
            <Name>Craig Hernandez</NAME>
            <DATE>2013-01-01T00:00:00.000+08:00</DATE>
            <PRICE>31</PRICE>
            <PRODUCT>BPD</PRODUCT>
            </ROW>
            <ROW>
            <Name>Craig Hernandez</NAME>
            <DATE>2013-02-01T00:00:00.000+08:00</DATE>
            <PRICE>30</PRICE>
            <PRODUCT>BPD</PRODUCT>
            </ROW>

            Edited by: 990965 on Feb 28, 2013 8:30 AM
            • 3. Re: How can I use an IF ELSE statement and the xdoxslt: get_variable together?
              AlexAnd
              >
              1) I tried this and it didn't work:
              <?if: xdoxslt:get_variable($_XDOCTX,'BP4'),01 then xdoxslt:set_variable($_XDOCTX, 'JAN1',PRICE) else xdoxslt:set_variable($_XDOCTX, 'JAN1',0) end if?>
              <?xdoxslt:get_variable($_XDOCTX,'JAN1')?>
              <?end if?>

              2) I tried this and it didn't work:
              <?xdoxslt:ifelse(xdoxslt:get_variable($_XDOCTX,'BP4')='01',xdoxslt:set_variable($_XDOCTX, 'JAN1',PRICE),xdoxslt:set_variable($_XDOCTX, 'JAN1',0))?>
              <?xdoxslt:get_variable($_XDOCTX,'JAN1')?>
              <?end if?>

              3) I tried this and it didn't work:
              <?xdofx:if xdoxslt:get_variable($_XDOCTX,'BP4')='01' then xdoxslt:set_variable($_XDOCTX, 'JAN1',PRICE) else xdoxslt:set_variable($_XDOCTX, 'JAN1',0) end if?>
              <?xdoxslt:get_variable($_XDOCTX,'JAN1')?>
              >
              so
              <?xdoxslt:set_variable($_XDOCTX, 'JAN1', xdoxslt:ifelse(xdoxslt:get_variable($_XDOCTX,'BP4')='01', PRICE, 0))?>
              <?xdoxslt:get_variable($_XDOCTX,'JAN1')?>
              it's works for me