XPATH select by set of possible attribute values - arrays

I have this:
<database>
<exercise_muscle id="20" muscleID="1" exerciseID="1" />
<exercise_muscle id="35" muscleID="2" exerciseID="1" />
<exercise_muscle id="50" muscleID="3" exerciseID="2" />
<exercise_muscle id="50" muscleID="4" exerciseID="2" />
</database>
And I want to get the exercise_muscle nodes, which have e.g. muscleID value 1, 3 or 4.. so the set of possible values.
I know that I can use "or", but I was hoping there is some better solution.

how about this? (runs using xpath 2.0)
/database/exercise_muscle[#muscleID = ('1', '3', '4')]
alternatively, you can use
/database/exercise_muscle[#muscleID = '1' or #muscleID = '3' or #muscleID = '4']

Related

Adding two values and send them to the server in ReactJs

I am trying to add two values in my form to get the sum. One value is a number and the other is a string number and here is how they are implemented :
<AvGroup className="col-md-6">
<Label >Total Amount</Label>
<AvInput disabled type="number" name="total_amount" onChange={setFormValue}
value={(sumOfItems + parseInt(form.delivery_amount)) || ''} />
</AvGroup>
sumOfItems is a number and I am using parseInt to add a string value to it and then, send the result to the server. The problem is that I always get that error as a response from the server :
Cast to Number failed for value "NaN" at path total_amount
Any help on how I can fix this problem?!
If you want it to just work, change
value={(sumOfItems + parseInt(form.delivery_amount)) || ''}
to
value={(sumOfItems + (form.delivery_amount ? parseInt(form.delivery_amount)) : 0)}.
This will result in 0 being added to sumOfItems if parseInt can't parse out a number.

SQL Query XML with 'where' clause

I am trying to retrieve a single row of data based on an XML attribute.
The SQL I have so far is:
select C.query('.')
from Bookmarks
cross apply XMLValue.nodes('/rdBookmarks/Bookmark') as T(C)
The data returned from this query is (4 rows of data)
<Bookmark Report="DataExplorer" Name="DataExplorer" CustomColumn1="Analysis" CustomColumn2="Data Explorer" Description="Benefit Plan Count" SaveTime="2020-02-21T10:44:36-05:00" BookmarkID="79638e95-c5b7-43f1-b180-f5f31b50dea4" ExtraFile="Bookmarks_79638e95-c5b7-43f1-b180-f5f31b50dea4.xml">
<RequestParameters rdAgLoadSaved="Bookmarks_79638e95-c5b7-43f1-b180-f5f31b50dea4.xml" />
<SessionParameters />
</Bookmark>
<Bookmark Report="People.ContactInfo.EmergencyContactList" Name="" CustomColumn1="Report" CustomColumn2="Emergency Contact List" Description="Engineering Emergency Contacts" SaveTime="2020-02-21T11:48:28-05:00" BookmarkID="953e67ef-d45e-4fac-8d71-b2153a726612" FolderID="9ef9c6db-73d7-439e-b465-cc3c45d37397">
<RequestParameters inpMultiSelect_EmployeeStatus="" inpMultiSelect_Employer="" inpMultiSelect_OrgLevel1="22" inpMultiSelect_OrgLevel2="" inpMultiSelect_OrgLevel3="" inpMultiSelect_OrgLevel4="" inpMultiSelect_OrgLevel5="" inpMultiSelect_Manager="" inpMultiSelect_EmployeeType="" inpMultiSelect_SalariedHourly="" inpMultiSelect_ExemptStatus="" inpMultiSelect_JobTitle="" inpMultiSelect_State="" inpLastHireDate_Start="" inpLastHireDate_End="" inpEmpNo="" inpFirstName="" inpLastName="" inpCheckDate_Start="" inpCheckDate_End="" inpPeriodDate_Start="" inpPeriodDate_End="" inpMultiSelect_Category="" inpMultiSelect_EDTCode="" inpMultiSelect_Class1="" inpMultiSelect_Class2="" inpMultiSelect_Class3="" inpMultiSelect_Class4="" inpSelect_SelectionList="" inpMultiSelect_PostedStatus="" inpCheckBox_AllowBlankDates="" inpCheckBox_DefaultChecked_Manual="1" inpDate_SingleDate="" inpDate_Manual_SingleDate="" inpDateRange_Start="" inpDateRange_End="" inpDateRange2_Start="" inpDateRange2_End="" inpDateRange3_Start="" inpDateRange3_End="" inpDateRangeBlankDate_Start="" inpDateRangeBlankDate_End="" inpSelect_List="" inpMultiSelect_AnniversaryDateMonth="" inpMultiSelect_BenefitType="" inpMultiSelect_BenefitPlan="" inpMultiSelect_BirthDateMonth="" inpMultiSelect_BloodType="" inpMultiSelect_Event="" inpMultiSelect_EventLicenseCertif="" inpMultiSelect_NoteAuthor="" inpMultiSelect_NoteType="" inpMultiSelect_PastDue="" inpMultiSelect_PayFrequency="" inpMultiSelect_SalaryGrade="" inpMultiSelect_Skill="" inpMultiSelect_SourceData="" inpMultiSelect_SourceData2="" inpMultiSelect_UnionAffiliation="" inpMultiSelect_WaivedBenefit="" />
<SessionParameters />
</Bookmark>
<Bookmark Report="TotalRewards.Compensation.SalaryAnalysis" Name="" CustomColumn1="Analysis" CustomColumn2="Salary Analysis" Description="Annual Pay by Employee" SaveTime="2020-02-21T12:03:02-05:00" BookmarkID="30da52af-55d3-4c06-985a-12d428731773" ExtraFile="Bookmarks_30da52af-55d3-4c06-985a-12d428731773.xml">
<RequestParameters rdAgLoadSaved="Bookmarks_30da52af-55d3-4c06-985a-12d428731773.xml" />
<SessionParameters />
</Bookmark>
<Bookmark Report="Payroll.PayrollProcessing.PayrollAnalysis" Name="" CustomColumn1="Report" CustomColumn2="Payroll Analysis" Description="Payroll Age 40-49" FolderID="9ef9c6db-73d7-439e-b465-cc3c45d37397" SaveTime="2020-02-21T12:50:26-05:00" BookmarkID="2f02d5ab-b15d-46f3-a669-04ab6fbfdfbe" ExtraFile="Bookmarks_2f02d5ab-b15d-46f3-a669-04ab6fbfdfbe.xml">
<RequestParameters inpMultiSelect_EmployeeStatus="" inpMultiSelect_Employer="" inpMultiSelect_OrgLevel1="" inpMultiSelect_OrgLevel2="" inpMultiSelect_OrgLevel3="" inpMultiSelect_OrgLevel4="" inpMultiSelect_OrgLevel5="" inpMultiSelect_Manager="" inpMultiSelect_EmployeeType="" inpMultiSelect_SalariedHourly="" inpMultiSelect_ExemptStatus="" inpMultiSelect_JobTitle="" inpMultiSelect_State="" inpLastHireDate_Start="" inpLastHireDate_End="" inpEmpNo="" inpFirstName="" inpLastName="" inpCheckDate_Start="" inpCheckDate_End="" inpPeriodDate_Start="" inpPeriodDate_End="" inpMultiSelect_Category="" inpMultiSelect_EDTCode="" inpMultiSelect_Class1="" inpMultiSelect_Class2="" inpMultiSelect_Class3="" inpMultiSelect_Class4="" inpSelect_SelectionList="" inpMultiSelect_PostedStatus="" inpCheckBox_AllowBlankDates="" inpCheckBox_DefaultChecked_Manual="" inpDate_SingleDate="" inpDate_Manual_SingleDate="" inpDateRange_Start="" inpDateRange_End="" inpDateRange2_Start="" inpDateRange2_End="" inpDateRange3_Start="" inpDateRange3_End="" inpDateRangeBlankDate_Start="" inpDateRangeBlankDate_End="" inpSelect_List="" inpMultiSelect_AnniversaryDateMonth="" inpMultiSelect_BenefitType="" inpMultiSelect_BenefitPlan="" inpMultiSelect_BirthDateMonth="" inpMultiSelect_BloodType="" inpMultiSelect_Event="" inpMultiSelect_EventLicenseCertif="" inpMultiSelect_NoteAuthor="" inpMultiSelect_NoteType="" inpMultiSelect_PastDue="" inpMultiSelect_PayFrequency="" inpMultiSelect_SalaryGrade="" inpMultiSelect_Skill="" inpMultiSelect_SourceData="" inpMultiSelect_SourceData2="" inpMultiSelect_UnionAffiliation="" inpMultiSelect_WaivedBenefit="" rdAgLoadSaved="Bookmarks_2f02d5ab-b15d-46f3-a669-04ab6fbfdfbe.xml" />
<SessionParameters />
</Bookmark>
but this returns each Bookmark element (4 total). I would like to add a where clause to only return one Bookmark node based on the BookmarkID, but can't seem to figure out how to do this. Is there a way to add something like
where C.query('#BookmarkID') = '953e67ef-d45e-4fac-8d71-b2153a726612'
so that only one Bookmark node is returned?
You could use the value() method to get a single value:
SELECT C.query('.'), BookmarkID = c.value('#BookmarkID', 'VARCHAR(36)')
FROM Bookmarks
CROSS APPLY XMLValue.nodes('/rdBookmarks/Bookmark') as T(C)
WHERE c.value('#BookmarkID', 'VARCHAR(36)') = '953e67ef-d45e-4fac-8d71-b2153a726612'
You can also filter directly in the nodes() method:
SELECT C.query('.'), BookmarkID = c.value('#BookmarkID', 'VARCHAR(36)')
FROM Bookmarks
CROSS APPLY XMLValue.nodes('/rdBookmarks/Bookmark[#BookmarkID="953e67ef-d45e-4fac-8d71-b2153a726612"]') as T(C);

How to implement input text masking in React-Native?

The mask is needed: 90.99%, where:
9 - optional digit
0 - required
%,. - relevant characters '%' and '.'
For example:
Input / Result
1 ---> 1%
12 ---> 12%
12.1 ---> 12.1%
12.12 ---> 12.12%
I'm using redux-form
I've tried react-native-text-input-mask and react-native-masked-text already, however, there is no similar functionality in these packages (in the first one there is something similar, but '%' is correctly displayed only if it is used before the number but this char should be after)
The best way here is to provide masking next to the input itself.
It highly depends on how do you use the Field component (do you even use it?).
You can try to use the format prop on the Field.
Or you can provide your own component to render a field and provide own format functionality:
const renderPercentagedInput = (field) => {
function onChange(evt) {
const value = evt.target.value;
const numbers = value.replace(/[^0-9.,]/g, '')
field.input.onChange(numbers + '%')
}
return (
<TextInput
{...field.input}
onChangeText={onChange}
/>
);
}

angulars js client side validation on phone number unable to combine regex formats

The following formats are allowed for the phone number
xxx-xxx-xxxx [x represents a digit]
xxx.xxx.xxxx
xxxxxxxxxx [digit ten times]
I have the working sample for the formats but I am unable to combine them in a single regex. How to combine them into a single regex?
"/^[1-9]\d{2}-\d{3}-\d{4}|^\d{10}$/"
"/^[1-9]\d{2}[.]\d{3}[.]\d{4}|^\d{10}$/"
"/^\d{10}$/"
My regex code in angular:
<div class="form-group" ng-class="{'has-error':userprofileForm.phone.$touched && userprofileForm.phone.$invalid && userprofileForm.extension.$touched && userprofileForm.extension.$invalid}">
<label for="profile-phone" class="control-label">{{'PHONE'|translate }}</label>
<div>
<input name="phone" type="text" class="form-control" ng-model="userprofile.phoneNumber" ng-pattern="/^\d{10}$/" required="required" />
<div ng-show="userprofileForm.phone.$touched && userprofileForm.phone.$invalid">
<span ng-message="required">Please enter phone number</span>
</div>
</div>
</div>
You can combine them like so:
ng-pattern="/^([1-9]\d{2}-\d{3}-\d{4})|([1-9]\d{2}\.\d{3}\.\d{4})|(\d{10})$/"
Just put every pattern in its own group with () and or them together with |.
Or more compact using a back reference (assuming your third case should also not start with a 0):
ng-pattern="/^[1-9]\d{2}([.-]?)\d{3}\1\d{4}$/"
RegEx breakdown:
^ // start of line
[1-9] // match '1', '2', '3', '4', '5', '6', '7', '8' or '9'
\d{2) // match 2 digits
( // begin capturing group 1
[.-] // match '.' or '-'
? // make the preceeding [.-] optional, so capturing group 1 matches '.', '-' or nothing.
) // end capturing group 1
\d{3) // match 3 digits
\1 // back reference: match what was matched by capturing group 1
\d{4) // match 4 digits
$ // match end of line
Note that due to the use of the back reference a mix like xxx.xxx-xxxx is correctly rejected.
Here's a similar post with various answers including $filter, regex etc.
Do check it out..
Also this handy online regex validator explains your regex might help validate the syntax.
Hope this helps.

Multiple conditions for db_update

In Drupal 7 simple updates work like this:
$num_updated = db_update('joke')
->fields(array(
'punchline' => 'Take my wife please!',
))
->condition('nid', 3, '>=')
->execute();
But what if I have multiple conditions( say nid >=3 and uid >=2). Writing something like:
$num_updated = db_update('joke')
->fields(array(
'punchline' => 'Take my wife please!',
))
->condition('nid', 3, '>=')
->condition('uid', 2, '>=')
->execute();
does not seem to work. Any ideas?
What you have written will do the equivalent of:
'...WHERE (NID >= 3 AND UID >= 2)"
If you wanted an OR conditional you need to nest the statements as such (no, it's not very intuitive):
->condition(db_or()->condition('NID'', 3, '>=')->condition('UID', 2, '>='))
There is also db_and() [default for chaining multiple condition methods] and db_xor() that you can use when nesting.

Resources