I know the solution for this should be simple, but I can't figure it out.
When I add a number (for example 2) to page variable, it actually considers it as a string and shows: instead of 3 : 1+2
#{
var page= 1 ;
}
<li>#page+2</li>
Expression must be evaluated server side so it must be enclosed in parenthesis:
<li>#(page+2)</li>
If you don't then parser will evaluate server side only first token after #, page will be replaced with its value and you'll have <li>1+2</li> HTML text (where, of course, no more evaluation will be performed).
Related
I am new to SSIS and I am having an issue populating a derived column based on more than one criteria from strings in a column.
I have managed to get it working with a single criteria as an example:
FINDSTRING(OS,"Server",1) > 0 ? "Server" : "Desktop"
The above works and populates anything with server in the OS to "server" and everything else to "Desktop" but I have other strings that can identify a server. what I have tried as an example is:
FINDSTRING(OS,"Server", "Red Hat", "AIX",1) > 0 ? "Server" : "Desktop"
I basically have about 10 key words that id a server in the OS column so I want to output Server for these in the derived column and Desktop for anything without those strings.
Is that possible? I thought about doing 10 different find strings but I assumed the outputs would overwrite each other.
Thank you.
That's not valid syntax so no, what you're directly attempting won't work.
If you have a constrained list of values aka a static list for your server values then I would take the approach of adding 10 Derived Columns to your data flow.
They will take the following pattern of adding a new boolean (true/false) column to the data flow. You do not need to bring those values into your final table but you will use them to compute the final value of whether this is a desktop or server operating system.
DER HPUX
Add a derived column to the data flow and name it DER HPUX where the final word(s) are the server key word. You'll then add a new column to the using the FINDSTRING syntax and name it along the lines of your component name
hasHPUX FINDSTRING(LOWER([OS]), "hpux") > 0
Note that I have explicitly cast the OS to lower case here and do the same with my argument to findstring as I don't know for certain whether Red Hat will always be Red Hat and not red hat or RED HAT. You know your data better but that may help if the data is inconsistently formatted.
Repeat this pattern for all your keywords
DER IsServer
Here I'll create another intermediate column called IsServer and all I'm going to do is OR all the preceding has* named
hasHPUX || hasRedHat || hasAix || etc
DER Determine Server or Desktop
Finally, we're ready to use the newly created column of isServer to populate the column OSClass or whatever you want it called
(isServer) ? "Server" : "Desktop"
Wow, that's a lot of work, why in the world would you do all of that?
Testing.
You can't debug an expression. By breaking all of the complex logic down into tiny nibbles, you can put a Data Viewer in the package after the DER isServer and at a glance determine why something is or isn't setting the appropriate flag value.
Sure, you could do this in a single expression like the syntax you are trying but help your future self by not doing that. When your expression is so long you can't see all of it in the editor, it's time to break it into smaller units.
(FINDSTRING(LOWER([OS]), "hpux") > 0 || FINDSTRING(LOWER([OS]), "red hat") > 0 || FINDSTRING(LOWER([OS]), "aix")> 0 || etc) ? "Server" : "Desktop"
References
FINDSTRING
|| aka OR
?: aka ternary operator
I have a get request from where I am taking all the id values , using json extractor I have extracted and named it id and used match number as -1
Now I want to pass this id variable into a post url paths
And this post requests are set inside a for each controller to run for required no of iterations
I have given for each controller values as
Input variable : id
Start index : 0
End index : ${id_matchNr}
Output var name : outid
Paths arelike
Post Path 1: https://demo.qwe.com/blue${outid}
Post Path 2:
https://demo.qwe.com/blue${outid}
I want to pass only even id numbers to path 1 and odd id numbers to path two
So I have used if controller and gave expression as
${outid}%2==0 to first path
And ${outid}%2!=0 to other if controller and placed the path 2 request
And checked the interpret condition
These two rqsts are in for each controller.
When I run the script I am getting a blank output for the post rqsts.
Can you please help me out
The function or variable you put in the If Controller must evaluate to true, only this way the If Controller will run its children. In your case you're providing just a string.
You need to wrap it into i.e. __jexl3() function like:
${__jexl3(${outid}%2==0,)}
this way it should work as expected.
More information: 6 Tips for JMeter If Controller Usage
Sorry, but uhrm, I'd like to use regexp (actually I'd use something else but I want to do the task within a Matlab function) to pick a single row containing desired keywords within an html table.
I am using Matlab calling function regexpi (case-insensitive version of regexp), which is akin to PHP regex from what I can tell.
Ok, here's a snippet from such an html table to parse:
<tr><td>blu</td><td>value</td></tr><tr><td>findme</td><td>value</td></tr><tr><td>ble</td><td>value</td></tr>
The desired row to pick contains the word "findme".
(added:) Content of other cells and tags in the table could be anything (here "bla" is a dummy value)- the important part is the presence of "findme" and that a single line (not more) is caught (or all lines containing "findme" but such behaviour is not expected). Any paired name/value table in a wikipedia page is a good example.
I tinkered with https://regex101.com/ using whatever I could dig up at the Matlab documentation (forward/backward looking, combinations of :,> and ?), but have failed to identify a pattern that will pick just the right row (or all those that contain the keyword "findme"). The following pattern for instance will pick the text but not the entire row: <tr[^>]*>[^>]*.*?(findme).*?<\/td .
Pattern <tr[^>]*>(.*?findme.*?)<\/tr[^>]*> picks the row but is too greedy and picks preceding rows.
Note that the original task I had set out was to capture entire tables and then parse these, but the Matlab regexp-powered function I found for the task had trouble with nested tables (or I had trouble implementing it for the task).
The question is how to return a row containing desired keywords from an html table, programmatically, within a matlab function (without calling an external program)? Bonus question is how to solve the nested table issue, but maybe that's another question.
I suggest you split up the string with strsplit and use contains for the filtering, which is a lot more readable and maintainable than a regex pattern:
htmlString = ['<tr><td>blu</td><td>value</td></tr><tr><td><a',...
'href="bla">findme</a></td><td>value</td></tr><tr><td><a',...
'href="ble">ble</a></td><td>value</td></tr>'];
keyword = 'findme';
splitStrings = strsplit(htmlString,'<tr>');
desiredRow = ['<tr>' splitStrings{contains(splitStrings,keyword)}]
The output is:
<tr><td>findme</td><td>value</td></tr>
Alternatively you may also combine extractBetween and contains:
allRows = extractBetween(htmlString,'<tr>','</tr>');
desiredRow = ['<tr>' allRows{contains(allRows,keyword)} '</tr>']
If you must use regex:
regexp(htmlString,['<tr><td>[^>]+>' keyword '.*?<\/tr>'],'match')
Try this
%<td>(.*?)%sg
https://regex101.com/r/0Xq0mO/1
I've been trying to make this statement work for some time but have ultimately lost the will to live.
In essence, I am attempting to filter a report to only certain Locations (So if you want the query to only include locations "Avonmouth" and "Bedford", that's what it would include, filtering the rest out) I have done this by implementing a check box system, so you can easily add locations to the filter. Unfortunately I keep getting syntax problems with the SQL script. Its a bit of a butchery, so please forgive me, but I have included the SQL below. (CHKBE = The check box)
WHERE QryTraining IN ((IIf [Forms]![ReportDeployer]![CHKAV]<>"" ,"Avonmouth",x),(IIf [Forms]![ReportDeployer]![CHKBA]<>"" ,"Basingstoke",x),(IIf [Forms]![ReportDeployer]![CHKBT]<>"" ,"Bedford Transport",x),(IIf [Forms]![ReportDeployer]![CHKBW]<>"" ,"Bedford Warehouse",x),(IIf [Forms]![ReportDeployer]![CHKBE]<>"" ,"Belfast",x),(IIf [Forms]![ReportDeployer]![CHKCA]<>"" ,"Carluke",x),(IIf [Forms]![ReportDeployer]![CHKEX]<>"" ,"Exeter",x),(IIf [Forms]![ReportDeployer]![CHKKI]<>"" ,"Kidderminister",x),(IIf [Forms]![ReportDeployer]![CHKKN]<>"" ,
"Knowsley",x),(IIf [Forms]![ReportDeployer]![CHKTE]<>"" ,"Teva",x),(IIf [Forms]![ReportDeployer]![CHKWI]<>"" ,"Wickford",x),(IIf [Forms]![ReportDeployer]![CHKYO]<>"" ,"York",x))
Each time I attempt to run it, it throws it back with a Syntax error.
Thanks in advance, T.
Not sure this will work any better but parens are in wrong place at beginning of each IIf() and maybe need apostrophe delimiters:
WHERE QryTraining IN (IIf([Forms]![ReportDeployer]![CHKAV]<>"" ,"'Avonmouth'",x), IIf([Forms]![ReportDeployer]![CHKBA]<>"","'Basingstoke'",x), IIf([Forms]![ReportDeployer]![CHKBT]<>"","'Bedford Transport'",x), IIf([Forms]![ReportDeployer]![CHKBW]<>"","'Bedford Warehouse'",x), IIf([Forms]![ReportDeployer]![CHKBE]<>"","'Belfast'",x), IIf([Forms]![ReportDeployer]![CHKCA]<>"","'Carluke'",x), IIf([Forms]![ReportDeployer]![CHKEX]<>"","'Exeter'",x), IIf([Forms]![ReportDeployer]![CHKKI]<>"","'Kidderminister'",x), IIf([Forms]![ReportDeployer]![CHKKN]<>"","'Knowsley'",x), IIf([Forms]![ReportDeployer]![CHKTE]<>"","'Teva'",x), IIf([Forms]![ReportDeployer]![CHKWI]<>"","'Wickford'",x), IIf([Forms]![ReportDeployer]![CHKYO]<>"","'York'",x))
Probably need to use empty string or some text like "N/A" in place of the x.
A BOUND checkbox must be either True or False (Yes/No), never an empty string. An UNBOUND checkbox can be set for triple state, in which case it could return True/False/Null, again never an empty string. So I am not sure why comparison to empty string. Just test for True.
IIf([Forms]![ReportDeployer]![CHKAV], "'Avonmouth'", "")
In my HTML code I have
<option name="PRODUCTS" value="3">Products</option>
I need get both the name and value values in my server side Perl function through my Perl CGI param.
I can only get the value, is there a way to get the name also?
<option name="PRODUCTS" value="3">Products</option>
An <option> element does not have a name attribute, so this is invalid HTML and the browser will ignore it (except that it might make it available to JavaScript).
When the form is submitted, the browser will send to the server the name of the select coupled with the value of the selected option. This is the only information that the server will receive.
If you want to get 'PRODUCTS' then you will need to either:
Include it in the value: value="3-PRODUCTS" and then my ($number, $word) = split '-', $value
Look up the word that 3 is related to on the server (e.g. in a hash embedded in the script, or with a database query).
CGI::param() with no parameters returns all the names. Then CGI::param($name) will return all the values for a given name.
for my $name (CGI::param()) {
for my $val (CGI::param($name)) {
print "name: $name, value: $val\n";
}
}
Update: sorry, misread "option" as "input". option's name attribute isn't sent to the server at all, so there's no way to tell what it was without also having the html itself. You could add javascript to set a hidden input field to the option's name when it's chosen, though. What does populateCatArray do?
I would use the Vars method if there is some doubts on what is getting passed, especially if you have thee same 'name' used multiple times or a js its producing elements that don't exist on the page normally.
use CGI;
use Data::Dumper
my $q = new CGI;
print
$q->header({ type=>'text/plain' }),
Dumper($q->Vars);