Wildcards!

Yes, its been a while, Im sorry, mumble, mumble ... no excuses. Well other than its been, as my son would say 'hecka busy.' On a brighter note I see Kan has been posting some cool stuff in my absence, long may he continue! I received a question today asking about using a wildcard in a template, something like:
<?if:INVOICE = 'MLP*'?> where * is the wildcard 
Well that particular try does not work but you can do it without building your own wildcard function. XSL, the underpinning language of the RTF templates, has some useful string functions - you can find them listed here. I used the
starts-with
function to achieve a simple wildcard scenario but the
contains
can be used in conjunction with some of the others to build something more sophisticated. Assume I have a a list of friends and the amounts of money they owe me ... Im very generous and my interest rates a pretty competitive :0)
<ROWSET>
 <ROW>
  <NAME>Andy</NAME>
  <AMT>100</AMT>
 </ROW>
 <ROW>
  <NAME>Andrew</NAME>
  <AMT>60</AMT>
 </ROW>
 <ROW>
  <NAME>Aaron</NAME>
  <AMT>50</AMT>
 </ROW>
 <ROW>
  <NAME>Alice</NAME>
  <AMT>40</AMT>
 </ROW>
 <ROW>
  <NAME>Bob</NAME>
  <AMT>10</AMT>
 </ROW>
 <ROW>
  <NAME>Bill</NAME>
  <AMT>100</AMT>
 </ROW>
Now, listing my friends is easy enough
<for-each:ROW> <NAME> <AMT> <end for-each>
but lets say I just want to see all my friends beginning with 'A'. To do that I can use an XPATH expression to filter the data and tack it on to the for-each expression. This is more efficient that using an 'if' statement just inside the for-each.
<?for-each:ROW[starts-with(NAME,'A')]?>
will find me all the A's. The square braces denote the start of the XPATH expression.
starts-with
is the function Im calling and Im passing the value I want to check i.e. NAME and the string Im looking for. Just substitute in the characters you are looking for. You can of course use the function in a if statement too.
<?if:starts-with(NAME,'A')?><?attribute@incontext:color;'red'?><?end if?> 
Notice I removed the square braces, this will highlight text red if the name begins with an 'A' You can even use the function to do conditional calculations:
<?sum (AMT[starts-with(../NAME,'A')])?>
Sum only the amounts where the name begins with an 'A' Notice the square braces are back, its a function we want to apply to the AMT field. Also notice that we need to use ../NAME. The AMT and NAME elements are at the same level in the tree, so when we are at the AMT level we need the ../ to go up a level to then come back down to test the NAME value. I have built out the above functions in a sample template
here
. Huge prizes for the first person to come up with a 'true' wildcard solution i.e. if NAME like '*im*exter* demand cash now!
Comments:

Hi...
I have a Question..
I have a BIP report that accepts 6 parameters and all are text ...
Is it possible for the user to enter a wild card charater while entering a name in one of the parameters?
This works when user enter '%' as sql can handle this..
I want to know if there is another way of handling these wild card characters(especially '*' inplace of '%') in BIP input parameters.
Your help is appreciated.
Thanks.

Posted by guest on April 10, 2013 at 08:20 AM MDT #

How do I do a NOT start-with?
I've tried:
<?if:not starts-with(TAX_DESCR3,'EXCISE')?>
<?if:!starts-with(TAX_DESCR3,'EXCISE')?>

Posted by Paula on November 13, 2013 at 08:39 AM MST #

Hi Paula
Try

<?if:not(starts-with(TESTSTR,'This'))?>

Note the extra parentheses.

regards

Tim

Posted by Tim on November 13, 2013 at 10:50 AM MST #

I want to use the bi publisher to look for several conditions using a wild card. For example if I was sql it would look like this:

if name in ('%Wst','%Grt')

How can I utilize bi publisher to look for the same conditions.

Posted by guest on February 19, 2014 at 10:15 AM MST #

I have a follow up post coming on this using another method but you can chain XPATH commands together using 'or' and '|'
Will have post up soon
Tim

Posted by Tim on February 21, 2014 at 09:40 AM MST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Follow bipublisher on Twitter Find Us on Facebook BI Publisher Youtube ChannelDiscussion Forum

Join our BI Publisher community to get the most and keep updated with the latest news, How-to, Solutions! Share your feedback and let us hear your voice @bipublisher on Twitter, on our official Facebook page, and Youtube!

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today