How to merge(group) xpath results - xpath

I Have following table
<table>
<tbody>
<tr>
<td>First Row | First Column</td>
<td>First Row | Second Column</td>
</tr>
<tr>
<td>Second Row | First Column</td>
<td>Second Row | Second Column</td>
</tr>
<tr>
<td>Third Row | First Column</td>
<td>Third Row | Second Column</td>
</tr>
<tr>
<td>Forth Row | First Column</td>
<td>Forth Row | Second Column</td>
</tr>
<tr>
<td>Fifth Row | First Column</td>
<td>Fifth Row | Second Column</td>
</tr>
<tr>
<td>Sixth Row | First Column</td>
<td>Sixth Row | Second Column</td>
</tr>
</tbody>
I need to use xpath expresion to receive grouped 3 records:
First Row | Second Column, Second Row | Second Column
Third Row | Second Column, Forth Row | Second Column
Fifth Row | Second Column, Sixth Row | Second Column
How I can achive that using only xpath 1.0?

Here you go, xpath expression:
concat(//tr[1]/td[2], ' , ', //tr[2]/td[2], codepoints-to-string(10), //tr[3]/td[2], ' , ', //tr[4]/td[2], codepoints-to-string(10), //tr[5]/td[2], ' , ', //tr[6]/td[2])
The above will return the following string:
First Row | Second Column , Second Row | Second Column
Third Row | Second Column , Forth Row | Second Column
Fifth Row | Second Column , Sixth Row | Second Column

Related

How to show product sizes related to product using laravel?

I want to show product sizes related to product I already have made a relation b/w tables into database i just only want to know that when i click the specific product the size related to that product will be shown in the table.inside function how to make joining b/w three tables please make the join table using DB class because it will be easy to understand for me thanks.
Does Anyone have an idea ?
please check product sizes image
https://i.stack.imgur.com/Yt6Jk.png
Database
product_sizes table
----------------------------------------------------
id | size_name | Body_length | Body_width |
----------------------------------------------------
1 | M | 2.3 | 3.4
2 | L | .5 | 4.4
3 | s | 2.5 | 3.2
4 | xs | 3.5 | 2.4
products table
----------------------------------------
id | product_name | Description |
----------------------------------------
1 Ultraclub 1 | Ultraclub 300 |
2 Ultraclub 2 | Ultraclub 200 |
3 Ultraclub 3 | Ultraclub 500 |
4 Ultraclub 4 | Ultraclub 600 |
5 Ultraclub 5 | Ultraclub 400 |
available_product_sizes table
----------------------------------------
id | product_id | product_size_id
----------------------------------------
1 | 2 | 1
2 | 3 | 4
3 | 4 | 3
4 | 1 | 2
5 | 2 | 3
Controller
public function single_product($product_slug){
$Sizes=DB::table('product_sizes')->get();
$single_product=DB::table('products')->where('product_slug',$product_slug)->get();
return view('front_end/single_product',compact('single_product','Sizes'));
}
html view
<div class="product-tabs__pane product-tabs__pane--active" id="chart">
<table class="table table-bordered text-center">
<tr style="background-color:#3366cc;color:white">
<td><b>Sizes</b>
</td>
<td><b>Body length</b>
</td>
<td><b>Body width</b>
</td>
<td><b>Sleeve length</b>
</td>
</tr>
#foreach($Sizes as $size)
<tr>
<td><b>{{$size->sizes_name}}</b>
</td>
<td>{{$size->Body_length}}</td>
<td>{{$size->Body_width}}</td>
<td>{{$size->Sleeve_length}}</td>
</tr>
#endforeach
</table>
</div>
I assume you're already has/desfined many-to-many relationship between products and product_sizes tables
//App\Product.php
public function sizes()
{
return $this->belongsToMany('App\ProductSize', 'available_product_sizes', 'product_id', 'product_size_id');
}
//App\ProductSize.php
public function products()
{
return $this->belongsToMany('App\Product', 'available_product_sizes', 'product_size_id', 'product_id');
}
In order to get available product sizes you can use :
$sizes = App\Product::find(1)->sizes()->orderBy('size_name')->get();
Controller fix
public function single_product($product_slug) {
$single_product = Product::with('sizes')->where('product_slug',$product_slug)->first();
return view('front_end/single_product',compact('single_product'));
}
View Fix
//...
#foreach($single_product->sizes as $size)
<tr>
<td>
<b>{{$size->sizes_name}}</b>
</td>
<td>{{$size->Body_length}}</td>
<td>{{$size->Body_width}}</td>
<td>{{$size->Sleeve_length}}</td>
</tr>
#endforeach
//...
Answer to the question without using eloquent
use Illuminate\Support\Facades\DB; //include this
$products = DB::table('products as p')
->join('available_product_sizes as aps','aps.product_id','p.id')
->join('product_sizes ps','ps.id','aps.product_size_id')
->where('product_slug',$product_slug)->get();
But it is highly recommended to use eloquent relationships.

Group select options if description is the same

So I have a select that the options are froma laravel Foreach
#foreach($courseMonth as $cm)->groupBy('description');
<optgroup label="{{ nameMonth($cm->month) }}">
#foreach($days as $date)
#if(date('m', strtotime($date['date'])) == $cm->month)
<option value="{{ date('d/m/Y', strtotime($date['date'])) ." - ". $date['hours'] }}">{{ $date['description'] . ' - ' . date('d/m/Y', strtotime($date['date'])) . ' - ' . $date['hours'] . ' ('. $date['total'] . 'h)'}}</option>
#endif
#endforeach
</optgroup>
<?php $i++;?>
#endforeach
This is the options. And I want if $date['description'] is the same in two options, to combine both options. More detailed, if three options have their description as "Work", to combine all of the options.
I've tried a groupby in front of the foreach
#foreach($courseMonth as $cm)->groupBy('description');
But this didn't do anything. The table for the options only has one row (ex: One row has only one description but it can have multiple day options in the select) so I need to group those only when there is the same description in two options.
Table structure:
-----------------------------------------------
| id | description | date | hours | total |
|---------------------------------------------|
| 4 | work |2019-23-4 | 14h | 6h |
| 5 | work |2019-23-5 | 13h | 5h |
| 6 | school |2019-23-5 | 13h | 5h |
-----------------------------------------------
So the first two would appear in the same option and the last one as the second option of the select.

Hidding (Blank) Data in PivotGrid

1/. My DataBase SquetchUp , and Request:
I have those 2 table :
Table_EC: Table_P:
+------+---------+------------------+ +---------+--------+--------+
| Name | IdValue | ManyOtherInfo... | | IdValue | Value1 | Value4 |
+-----------------------------------+ +---------------------------+
| STR | INT | ManyTYPE | | Int | Label | OrderBy|
+------+---------+------------------+ +---------+--------+--------+
In order to diplay in a cross table I do this request:
SELECT NAME , VALUE1
FROM Table_EC
RIGHT JOIN Table_P
ON Table_EC.VALUE1= Table_P.VALUE1
ORDER BY PAR_VALEUR4
2/. Telerik MarkUp
My RadPivotGrid declaration:
<telerik:RadPivotGrid ID="RadPivotGrid1" runat="server" OnNeedDataSource="RPG_RECAP_NeedDataSource" >
<TotalsSettings RowGrandTotalsPosition="None" RowsSubTotalsPosition="None" />
<Fields>
<telerik:PivotGridAggregateField GrandTotalAggregateFormatString="" CalculationExpression=""
UniqueName="Statut" DataField="Value1" Aggregate="Count" >
<TotalFormat Level="0" Axis="Columns" TotalFunction="NoCalculation" SortOrder="Ascending"></TotalFormat>
</telerik:PivotGridAggregateField>
<telerik:PivotGridRowField UniqueName="RowCLI" DataField="Name" />
<telerik:PivotGridColumnField UniqueName="ColumnStatut" DataField="Value1" />
</Fields>
</telerik:RadPivotGrid>
3/. Current Result:
The expected result are the same but with out the (Blank) Row
How do i achieve this ?
For now my answer is : You can't
What i have done to "fix the issue":
( By fix I mean make the information more relevant for the Customer)
Count on a null value in the AggregateField Here ValueID.
Not on Value1 will make blank row display 0 .
Dont forget to set IgnoreNullValues="true" and ShowGroupsWhenNoData="false".

Putting delay until next page is loaded fully in Selenium IDE

I am trying to automate a test case using selenium IDE. I have installed this add-on on firefox. I am trying to login using admin/admin credentials in one of the websites and after that it takes couple of seconds to load the next page fully.
<tr>
<td>type</td>
<td>id=username</td>
<td>admin</td>
</tr>
<tr>
<td>type</td>
<td>id=password</td>
<td>admin</td>
</tr>
<tr>
<td>click</td>
<td>css=button.btn</td>
<td></td>
</tr>
<tr>
<td>waitForPageToLoad</td>
<td>30000</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=span.ncs-tree-nav</td>
<td></td>
</tr>
waitForPageToLoad is not working, ideally it should wait for 30 seconds but as soon as login button gets clicked, test case throws error as it is not able to find next element on the page.
Here is the output from IDE :-
[info] Executing: |open | /login.html | |
[info] Executing: |type | id=username | admin |
[info] Executing: |type | id=password | admin |
[info] Executing: |click | css=button.btn | |
[info] Executing: |waitForPageToLoad | 30000 | |
[info] Executing: |click | css=span.ncs-tree-nav | |
[error] Element css=span.ncs-tree-nav not found
As soon as login is done, it moved for searching expected navigation and error came.
It will be helpful if someone can point out if I missed something.
A pragmatic approach,
If you have some visual condition that gets true just when the page is loaded, you can look for that.
Say that the text "Welcome User" gets displayed in a span with id=content somewhere when the page is loaded, you can replace your waitForPageToLoad with
<tr>
<td>waitForText</td>
<td>id=content</td>
<td>Welcome*</td>
</tr>
Possibly you can even be as blunt as
<tr>
<td>waitForText</td>
<td>//body</td>
<td>*Welcome*</td>
</tr>
though I haven't tested the latter myself.
If your page reloads after clicking, you have to use clickAndWait instead of click:
<tr>
<td>clickAndWait</td>
<td>css=button.btn</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=span.ncs-tree-nav</td>
<td></td>
</tr>
If the page does not reload, upper code won't work. In this case wait for a presence of an element that you are going to use on the next step:
<tr>
<td>click</td>
<td>css=button.btn</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>css=span.ncs-tree-nav</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=span.ncs-tree-nav</td>
<td></td>
</tr>

Sum of a table column - SMARTY

I have a multidimensional associative array, which I pass to a smarty template. I use below code in my smarty template to generate the shown two tables in my browser.
The smarty code:
<!--language:smarty-->
{foreach from=$allarr key=header item=table}
<h5>{$header}</h5>
<table>
<tr>
<td>{t}Emp #{/t}</td>
<td>{t}Employee Name{/t}</td>
<td>{t}Amount{/t}</td>
</tr>
{foreach from=$table item=sub}
<tr>
<td>{$sub.emp_num}</td>
<td>{$sub.user_name}</td>
<td>{$sub.amount}</td>
</tr>
{/foreach}
<tr>
<td colspan="2">{t}Variation Total{/t}</td>
<td colspan="1">{t}+++{/t}</td>
</tr>
</table>
{/foreach}
The tables:
Table One
________________________________
Emp # |Employee Name |Amount |
________|_______________|_______|
1000001 | Test User | 775.00|
26 | user1 | 555.00|
________|_______________|_______|
Variation Total | +++ |
________________________|_______|
Table Two
______________________________
Emp # |Employee Name| Amount|
________|_____________|_______|
1000001 | Test User | 110.00|
________|_____________|_______|
Variation Total | +++ |
______________________|_______|
What I want, is to replace the "+++" with the actual sum of the values in each Amount column. Nothing seems to work. Can anyone help? Thanks in advance.
Figured out a way. :)
The complete code is below.
{foreach from=$allarr key=header item=table}
<h5>{$header}</h5>
<table>
<tr>
<td>{t}Emp #{/t}</td>
<td>{t}Employee Name{/t}</td>
<td>{t}Amount{/t}</td>
</tr>
{foreach from=$table item=sub}
<tr>
<td>{$sub.emp_num}</td>
<td>{$sub.user_name}</td>
<td>{$sub.amount}</td>
</tr>
{assign var="sum" value="`$sum+$sub.amount`"}
{/foreach}
<tr>
<td colspan="2">{t}Variation Total{/t}</td>
<td colspan="1">{t}{$sum}{/t}</td>
{assign var="sum" value=0}
</tr>
</table>
{/foreach}

Resources