Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Friday, 27 June 2014

Check a field exists in the XML with BI Publisher

this turned in to a bit of a GOTYA!  we had an interesting issue where mike was using a language field to control how a field looked on the page.  the trouble was we occasionally got crap data where the language field had not been populated  and the default section in a choose statement wasn't firing

the solution turned out to be

<?if:not(element_name)?> desired behavior when the element is not present <?end if?>
 which fixed the problem nicely  thank you google we love you !!!!!!!

Thursday, 1 May 2014

BI Publisher Date functions

Big Shout out to Jamie on this one :)   I hadn't really had to look for these before but as well as the Date field in the properties bit of the XML which i think shows the date the XML is created   there's also this cracking list of  Date functions out there that i think are going to come in really reallyBIP Date Functions Type Linky !!! useful

Tuesday, 1 April 2014

BI Publisher Handy snippets for checking if feilds exist and are populated

I found this when lurking about the interwebs looking for  a way to check if a field existed in the XML


• To define behavior when the element is present and the value is not null, use the following:
<?if:element_name!=?> desired behavior when the element exists and is not null <?end if?>
• To define behavior when the element is present, but is null, use the following:
<?if:element_name and element_name="?> desired behavior when the element exists but value is null <?end if?>
• To define behavior when the element is not present, use the following:
<?if:not(element_name)?> desired behavior when the element is not present <?end if?>

Monday, 31 March 2014

BI Publisher Sub templates and calling them conditionally

I had a few issues today that sent me off on an oddesy to learn about sub templates and how to use them . and now I've had a fiddle with them they have totally revised my approach to writing templates.  there really dead useful :).

 I'm working on one of our company invoices and  was having quite an unpleasant time trying to work out how the hell to make this template work . like every one else out there I should imagine our invoices can have  lots of different ways to display a line item and you can have any number of line items on a page how on earth was I going to cope with invoices that went over to more than one page ?????   this is the type of thing that on more than one ocasion has reduced me and Mike to sobbing wrecks and reaching for the poultry with one hand and the Whisky with the other when we tried to do this with transform

dead easy it turns out.

This where sub templates come in .  Sub templates are small templates in there own right that you can either store in another RTF document  or stick at the bottom of your template out of the way (which is what i did  in this case) 

My first issue was to make sure the header and footer on each page were there and displayed properly . I  had one header section which is displayed on every page  and 2 footers. one which is displayed on the last page  and one  on all the others . so I created these  as sub templates.  to do that i just wrapped them in <?Template:?> tags  like this 













then i just popped <?call-Template: PageHeadder?> in the  header of my word RTF Template. 

Next I tackled the footer issue by doing exactly the same I created 2 Templates  a page footer one and an last page footer one  then used a choose statement to choose which one to display in the footer  using a bit of code like this 

<?choose:?>
          <?when:PrintTax_ID5=“Y“?><?call:PageFooterWithTax?><?end when?>
           <?otherwise:?><?call:PageFooterNoTax?><?end otherwise?>
<?end choose?>


finally I created a sub template for each of the different line types i had  and used exactly the same technique to call the sub template for the line type i wanted to display .  yet again  no swearing sobbing or poultry bothering required 

Wednesday, 19 March 2014

BI Publisher Storeing a substring of an XML tag into a variable

this gave me a bit of  a headache  I had a task where i needed to chop of the last  character of one of the XML tags so I could use it in some of the logic statements  further down in the code  .  this did the trick  OptioPrinterName_ID180  is the name of the XML tag i wanted to chop the end off and store  and 1 at the end  is the number of characters to chop


<?xdoxslt:set_variable($_XDOCTX, ‘optioChar’,xdoxslt:right(OptioPrinterName_ID180,1))?> 

 Then further down in the code when i needed  to reference the variable for my logic  i Referenced it as follows


<?choose:?>
         <?when:xdoxslt:get_variable($_XDOCTX, ‘optioChar’)=‘A‘?>Test<?end when?>
           <?otherwise:?>Test2<?end otherwise?>
<?end choose?>