How to get second td class if i know first - xpath

My first question here, sorry if i do something wrong.
I have code
<div class="detail_block_param">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="name">1st par</td>
<td class="value">Swiss</td>
</tr>
</table>
</div><div class="detail_block_param">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="name">2nd par</td>
<td class="value">mechanic</td>
</tr>
</table>
I need to get "value" class if name="1st par".
I try
//h:td[2][*[contains(.,'1st par')]]/../h:td[last()]/h:a/text()
but its not worked for me.
Thanks!

Try something like:
'//td[#class="name"][contains(text(), "1st par")]/following-sibling::td[#class="value"]'

If you wish to do it using JQuery...Here is the solution:
$(".detail_block_param td:contains('1st par')").next().html()
Fiddler result for the same:
http://jsfiddle.net/CPQ8C/

Related

Why Xpath 3.0 works, but Xquery 3.0 doesn't work with the same expression

I launched Xpath in Oxygen. In Xpath 3.0 found what i need but in Xquery 3.0 doesn't find.
This is my Xpath expression
//table[tbody/tr/th/p[contains(text(), 'All Water System Contacts')]]/tbody/tr[3]/td[1]
This is my xml code
I put part code.
<table border="1" cellpadding="1" cellspacing="1" summary="." width="640">
<tbody>
<tr>
<th colspan="3">
<p>All Water System Contacts </p></th>
</tr>
<tr>
<th>Type</th>
<th>Contact</th>
<th>Communication</th>
</tr>
<tr>
<td align="center">AC - Administrative Contact - GENERAL MANAGER </td>
<td align="center">GRANT, JOHN, W <br/> PO BOX 869<br/> BIG SPRING, TX 79721-0869 </td>
<td align="center">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse"
width="100%">
<tbody>
<tr>
<th><b>Electronic Type</b></th>
<th><b>Value</b></th>
</tr>
</tbody>
</table>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse"
width="100%">
<tbody>
<tr>
<th><b>Phone Type</b></th>
<th><b>Value</b></th>
</tr>
<tr>
<td align="center">BUS - Business</td>
<td align="center">432-267-6341 </td>
</tr>
<tr>
<td align="center">FAX - Facsimile</td>
<td align="center">432-267-3121 </td>
</tr>
<tr>
<td align="center">BUS - Business</td>
<td align="center">432-267-6070 </td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td align="center">OW - Owner </td>
<td align="center">COLORADO RIVER MUNICIPAL WATER DISTRICT <br/> PO BOX 869<br/> BIG
SPRING, TX 79721-0869 </td>
<td align="center"> </td>
</tr>
</tbody>
</table>
I tried different functions.
I don't know why it doesn't work and what difference
Please help me.
I suspect your real, complete input has an XHTML default namespace declaration xmlns="http://www.w3.org/1999/xhtml" and in oXygen for XPath you have the setting enabled to "use the default namespace of the root element" so your path works with XPath out of the box while for XQuery you need to make sure you explicitly set
declare default element namespace 'http://www.w3.org/1999/xhtml';
in the prolog of your XQuery file or code sample.

Division by zero ErrorException in Table.php line 173: in laravel dompdf converter

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="700" style="max-width:700px;background:white;padding: 10px;">
<tr>
<td align="center">
<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="color: brown;font-size: 18px;font-weight: bold;">Walkover Web Solutions Private Limited</td>
</tr>
</table>
</td>
</tr>
I am getting the division by zero error while converting this html to pdf by dompdf. May I know what i am doing wrong here.
got the fix where it was causing problem. Looks like it this dompdf don't accept the cellpadding="0" cellspacing="0" in table styling. After removing the this from the style of table it worked fine. Even though design was not upto the mark but still this error got resolved
Each (open td) and (closed td) must write in different line instead of same line.
Example:
<td>
This is correct way.
</td>
<td>This is wrong way</td>
Remove the attribute width="100%" for the tables. doing this fixed the issue for me.
When I update laravel-dompdf package
v1.1.1 => v1.2.0
I face this error
Division by zero
after Debugging I found that you can not use cellpadding="0" cellspacing="0" together with width: 100%;
Incorrect Way:
<table width="100%" cellpadding="0" cellspacing="0">
</table>
Correct Way:
<table width="100%">
</table>
<table style="width: 100%;">
</table>
<table cellpadding="0" cellspacing="0">
</table>
Note: Your CSS Styling may effect

Mailchimp edit table cell background color

Is there any logical way to change the background colour for a table cell in a repeatable region in mailchimp? Here is my code, I don't see any options in mailchimp with the custom template build.
<table width="100%" cellspacing="20" mc:repeatable="product" mc:variant="content1">
<tbody>
<tr>
<td align="center" bgcolor="#ff0000" valign="middle" mc:edit="playlist"><h2>Playlist</h2>
<h3>Check out this playlist!</h3>
<h4>FOLLOW</h4></td>
</tr>
</tbody>
</table>
I came across a similar issue today. Here's a possible solution:
<table width="100%" cellspacing="20" mc:repeatable="product" mc:variant="red">
<tbody>
<tr>
<td align="center" bgcolor="#ff0000" valign="middle" mc:edit="playlist">
<h2>Playlist</h2>
<h3>Check out this playlist!</h3>
<h4>FOLLOW</h4>
</td>
</tr>
</tbody>
</table>
<table width="100%" cellspacing="20" mc:repeatable="product" mc:variant="green">
<tbody>
<tr>
<td align="center" bgcolor="#00ff00" valign="middle" mc:edit="playlist">
<h2>Playlist</h2>
<h3>Check out this playlist!</h3>
<h4>FOLLOW</h4>
</td>
</tr>
</tbody>
</table>
<table width="100%" cellspacing="20" mc:repeatable="product" mc:variant="blue">
<tbody>
<tr>
<td align="center" bgcolor="#0000ff" valign="middle" mc:edit="playlist">
<h2>Playlist</h2>
<h3>Check out this playlist!</h3>
<h4>FOLLOW</h4>
</td>
</tr>
</tbody>
</table>
When you've imported this into your template, create a campaign and on the design page you'll have a dropdown with the different colour options. Make any h2s, h3s etc editable by adding mc:edit.

How to get TD text by TH name?

I'm using scrapy to parse a doc, this code is like my code structure that I want to parse, I want to get TD text by TH name, How ?
<div id="m_PanelField">
<table width="100%" cellspacing="1" border="0">
<tbody>
<tr>
<th>Etat</th>
<td>XyXy</td>
</tr>
<tr>
<th>IP</th>
<td>XX.XX.XX.XX</td>
</tr>
<tr>
<th>Alias</th>
<td>lorem ipsum</td>
</tr>
</tbody>
</table>
</div>
//td[../th='Etat'] OR .//tr[th='Etat']/td
Thank's for #helderdarocha and #paul-trmbrth

problems with xpath evaluation

If I want to extract hrefs only under Type1, basically, 1,2,3,4. htm but not including 5.htm, how to do that?
What I have for now is ://table[#class='leftnav']//a"
Thanks !
<table width="240" border="0" cellpadding="0" cellspacing="0" class="leftnav">
<tr class="leftnav">
<th>Type1</th>
</tr>
<tr class="leftnav">
<td>2013</td>
</tr>
<tr class="leftnav">
<td>2012</td>
</tr>
<tr class="leftnav">
<td>2011</td>
</tr>
<tr class="leftnav">
<td>2010</td>
</tr>
<tr class="leftnav">
<th>Type2</th>
</tr>
<tr class="leftnav">
<td>2013</td>
</tr>
</table>
Try this xpath:
//tr[(preceding-sibling::tr/th)[last()]="Type1"]/td/a

Resources