What I do select first/second or forth td content with XPath - dom

<table class="attributes">
<tbody>
<tr>
<td class="label title"><b>scale</b></td>
<td class="value">1/48</td>
<td class="label title"><b>products</b></td>
<td class="value">Plastic kits</td>
</tr>
<tbody>
</table>
Hit a brain block on this one...
Trying to capture specific values within the td's. So the first time around I'll grab the first, then the second and so on...
//table[#class='attributes']/tbody/tr//descendant::td[#class='value']
Gives me all the td values how to select only the 2nd or 3rd.
I've tried:
"//table[#class='attributes']/tbody/tr//descendant::td[#class='value']/td[2]"
With no success.
For example:
$x("//*[#class='attributes']/tbody/tr/td[#class='value']")
finds me
[<td class=​"value">​1/48​</td>​, <td class=​"value">​Plastic kits​</td>​, <td class=​"value">​Limited edition​</td>​, <td class=​"value">​Aircraft​</td>​, <td class=​"value">​Eduard​</td>​, <td class=​"value">​0.5 kg​</td>​]
So then I changed the XPath to:
$x("//*[#class='attributes']/tbody/tr/td[#class='value'][1]")
adding the [1] and what it does is returns
[<td class=​"value">​1/48​</td>​, <td class=​"value">​Limited edition​</td>​, <td class=​"value">​Eduard​</td>​]

To select all of the class='value' td elements beneath the class='attributes' table:
/table[#class='attributes']//td[#class='value']
selects:
<td class="value">1/48</td>
<td class="value">Plastic kits</td>
To select just the second such td:
(/table[#class='attributes']//td[#class='value'])[2]

Related

Using TinyMCE with handlebars template

I am trying to use TinyMCE to allow my users to modify a handlebars report template. The template contains several elements that are not valid to TinyMCE and they are being moved around. See the {{#each data}} and {{/each}}
Here is good HTML code for my handlebars template:
<table class="table table-bordered">
<thead>
<tr>
<th><h4>Item</h4></th>
<th><h4 class="text-right">Quantity</h4></th>
<th><h4 class="text-right">Rate/Price</h4></th>
<th><h4 class="text-right">Sub Total</h4></th>
</tr>
</thead>
<tbody>
{{#each Details}}
<tr>
<td>{{Item}}<br><small>{{Description}}</small></td>
<td class="text-right">{{Quantity}}</td>
<td class="text-right">{{Rate}} {{UnitOfMeasure}}</td>
<td class="text-right">{{Amount}}</td>
</tr>
{{/each}}
</tbody>
</table>
After I past the code into TinyMCE, it results to the following:
{{#each Details}}{{/each}}
<table class="table table-bordered">
<thead>
<tr><th>
<h4>Item</h4>
</th><th>
<h4 class="text-right">Quantity</h4>
</th><th>
<h4 class="text-right">Rate/Price</h4>
</th><th>
<h4 class="text-right">Sub Total</h4>
</th></tr>
</thead>
<tbody>
<tr>
<td>{{Item}}<br /><small>{{Description}}</small></td>
<td class="text-right">{{Quantity}}</td>
<td class="text-right">{{Rate}} {{UnitOfMeasure}}</td>
<td class="text-right">{{Amount}}</td>
</tr>
</tbody>
</table>
Has anyone ran across a plugin or something else that may help me?
I just ran into this... I have an order confirmation email that I need to be configurable with a list of order items in a table; same issue.
I did just realize I probably shouldn't be using tables anyway, since they are not responsive, but I ultimately was able to solve the problem with HTML comments, like this:
<tr style="font-weight: bold;">
<td style="width: 145px;">Qty</td>
<td>Item</td>
<td>Unit Price</td>
<td>Total</td>
</tr>
<!--{{#order.line_items}} -->
<tr repeat="">
<td style="width: 145px;">{{quantity}}</td>
<td>{{product.name}}</td>
<td>{{currency unit_price}}</td>
<td>{{currency total}}</td>
</tr>
<!--{{/order.line_items}} -->
<tr>
<td style="width: 145px;"> </td>
<td> </td>
<td><strong>Subtotal:</strong></td>
<td>{{currency order.subtotal}}</td>
</tr>
I was able to use a custom attribute on my Element and use:
<tr repeat="{{#each Details}}">
</tr repeat="{{/each}}">

Align images in github-flavored-markdown

I have these badges in my Github repo:
How can I make them align to left (the 2 above) and to right the one under?
They are in the format ![description](url)
One way would be to use html table (since markdown table in GFM doesn't support merged cell)
this, for instance, seems to align the pictures properly within a README.md file.
<table >
<tr>
<td align="left"><img src="http://icons.iconarchive.com/icons/iconka/cat-commerce/48/add-icon.png"/></td>
<td align="right"><img src="http://icons.iconarchive.com/icons/iconka/cat-commerce/48/info-icon.png"/></td>
</tr>
<tr>
<td colspan="2"><img src="http://icons.iconarchive.com/icons/shwz/disney/512/pumbaa-icon.png"/></td>
</tr>
</table>
Result:
In your case:
<table>
<tr >
<td><img src="https://api.travis-ci.org/axemclion/grunt-saucelabs.png?branch=master"/></td>
<td align="right"><img src="https://saucelabs.com/buildstatus/grunt-sauce"/></td>
</tr>
<tr>
<td colspan="2"><img src="https://saucelabs.com/browser-matrix/grunt-sauce.svg"/></td>
</tr>
</table>
Which gives:

How to get rows of specific table and cells of specific row only

I have table with id parentTable. Also there is child table in the third column of every row. When i count the length of rows of parent table it gives me sum of rows of parent and child table. Also this happens with the tds. How do i achieve this for getting/iterating rows of parent table only and interating tds of parent rows only. I tried $('parentTable >tbody>tr') but not worked for me. Please assist. Below is the sample.
<table id="parentTable"><tr>
<td></td>
<td></td>
<td>
<table>
<tr>
<td></td><td></td>
</tr>
<tr>
<td></td><td></td>
</tr>
</table>
</td>
</tr>
<td></td>
<td></td>
<td>
<table>
<tr>
<td></td><td></td>
</tr>
<tr>
<td></td><td></td>
</tr>
</table>
</td>
</tr>
</table>
You can assign different classes to the rows (tr s) of the parent table, and the child table. And use those classes for selecting them. You can do the same for the cells (tds) too.
For example, you if your table looks like -
<table class="parentTable">
<tr class="parentRow">
<td class="parentCell">Cell 1</td>
<td class="parentCell">Cell 2</td>
<td class="parentCell">
<table class="childTable">
<tr class="childRow">
<td class="childCell">Cell 31</td>
<td class="childCell">Cell 32</td>
<td class="childCell">Cell 33</td>
</tr>
</table>
</td>
</tr>
</table>
In your jquery, to get just the parent rows and their cells you can use
$.each($(".parentRow"), function() {
$.each($(this).find(".parentCell"), function() {
//Do Something
});
});

Mailchimp: How to limit number of items in the RSS to Email campaign

I have my template set up to repeat a block of html between the |RSSITEMS:| tag, but my question is how to limit the number of times that block gets repeated.
Thank you in advance.
The best solution that I've found is to use MailChimps |FEEDITEMS| merge tag as it offers more granular control than the |RSSITEMS| tag. Here's a snippet for creating a repeatable block that only pulls the 5 most recent items in an automated-RSS campaign (notice the "$count=" declaration):
*|FEEDBLOCK:http://website.com/feed/|*
<table width="600" align="center" cellpadding="0" cellspacing="0">
*|FEEDITEMS:[$count=5]|*
<tr>
<td valign="middle" align="center">*|FEEDITEM:TITLE|*</td>
</tr>
<tr>
<td valign="middle" align="center">*|FEEDITEM:DATE|*</td>
</tr>
<tr>
<td valign="middle" align="center">*|FEEDITEM:CONTENT_FULL|*</td>
</tr>
*|END:FEEDITEMS|*
</table>
*|END:FEEDBLOCK|*

Switching to jQuery 1.5 breaks a selector

just upgraded to jQuery 1.5 and now it seems the find() has problems with several selctores:
var $AlertColumn = $('[name=TABLE_1] tr').find('.SAPBEXstdData:eq(9), .SAPBEXstdDataOdd:eq(9), td.SAPBEXaggData:eq(9)');
as of 1.5 (and IE7), the thing hangs in IE7 with an error popup after a while that there's a script running forever.
It works perfect in 1.4.2.
ok here comes the code (to the first data row), I have to work on the Alert-Row which is the 9th having those classes used in find():
<TABLE class=SAPBEXCellspacing cellSpacing=1 cellPadding=0 width=1250 border=0 name="TABLE_1" sizcache="5" sizset="20"><TBODY sizcache="5" sizset="20">
<TR sizcache="5" sizset="21">
<TD noWrap colSpan=19 sizcache="5" sizset="21">
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 sizcache="5" sizset="21">
<FORM name=SAPBWUForm5 action=/sap/bw/BEx?SAP-LANGUAGE=DE&ITEM=TABLE_1&STATE_ID=4KXJZOX5URFHG6BQFFTKAJ0OH&STATELESS=X&LAST_MESSAGE_ID=0 method=post sizcache="5" sizset="21">
<TBODY sizcache="5" sizset="21">
<TR sizcache="5" sizset="22">
<TD class=SAPBEXScrollVert noWrap sizcache="5" sizset="22">
<TABLE cellSpacing=0 cellPadding=1 border=0 sizcache="5" sizset="22">
<TBODY sizcache="5" sizset="22">
<TR>
<TD class=SAPBEXTxtStd noWrap><IMG title="Erste Zeile" alt="Erste Zeile" src="/sap/bw/Mime/BEx/Icons/page_first_row_inact.gif" border=0></TD>
<TD class=SAPBEXTxtStd noWrap><IMG title="Vorherige Zeilen" alt="Vorherige Zeilen" src="/sap/bw/Mime/BEx/Icons/page_up_inact.gif" border=0></TD>
<TD class=SAPBEXTxtStd noWrap> <LABEL>Zeile</LABEL></TD>
<TD noWrap><INPUT class=SAPBEXTxtFldright id=DATA_ROW_FROM title="Zeile - Maximale Anzahl: 170" onchange=document.SAPBWUForm5.submit() size=3 value=1 name=DATA_ROW_FROM></TD>
<TD class=SAPBEXTxtStd noWrap>/ 170 </TD>
<TD class=SAPBEXTxtStd noWrap><A title="Nächste Zeilen" href="JavaScript:SAPBW(5,'','','68')"><IMG title="Nächste Zeilen" alt="Nächste Zeilen" src="/sap/bw/Mime/BEx/Icons/page_down.gif" border=0></A></TD>
<TD class=SAPBEXTxtStd noWrap><A title="Letzte Zeile" href="JavaScript:SAPBW(5,'','','170')"><IMG title="Letzte Zeile" alt="Letzte Zeile" src="/sap/bw/Mime/BEx/Icons/page_last_row.gif" border=0></A></TD></TR></TBODY></TABLE></TD></FORM></TR></TBODY></TABLE></TD></TR>
<TR></TR>
<TR>
<TD class=SAPBEXchaText noWrap>Profit Center</TD>
<TD class=SAPBEXchaText noWrap>Projektleiter</TD>
<TD class=SAPBEXchaText noWrap colSpan=2>Projekt</TD>
<TD class=SAPBEXchaText noWrap>akt. Status</TD>
<TD class=SAPBEXchaText noWrap>akt. Status Dat.</TD>
<TD class=SAPBEXchaText noWrap>Kredit Datum</TD>
<TD class=SAPBEXchaText noWrap>letzte Buchung</TD>
<TD class=SAPBEXstdItem noWrap>Kredit</TD>
<TD class=SAPBEXstdItem noWrap>Ist Q1 2010</TD>
<TD class=SAPBEXstdItem noWrap>Ist Q2 2010</TD>
<TD class=SAPBEXstdItem noWrap>Ist Q3 2010</TD>
<TD class=SAPBEXstdItem noWrap>Ist Q4 2010</TD>
<TD class=SAPBEXstdItem noWrap>Kredit %</TD>
<TD class=SAPBEXstdItem noWrap>FC Q3</TD>
<TD class=SAPBEXstdItem noWrap>FC Q4</TD>
<TD class=SAPBEXstdItem noWrap>Projektende</TD>
<TD class=SAPBEXstdItem noWrap>Alert</TD>
<TD class=SAPBEXstdItem noWrap>Notizen</TD></TR>
<TR>
<TD class=SAPBEXstdItem noWrap rowSpan=7>PC100</TD>
<TD class=SAPBEXstdItem noWrap rowSpan=3>Ammann Conrad</TD>
<TD class=SAPBEXstdItem noWrap>G000034</TD>
<TD class=SAPBEXstdItem noWrap>Techn. Zusammenarbeit China</TD>
<TD class=SAPBEXstdItem noWrap>k.a.</TD>
<TD class=SAPBEXstdItem noWrap>#</TD>
<TD class=SAPBEXstdItem noWrap>#</TD>
<TD class=SAPBEXstdItem noWrap>#</TD>
<TD class=SAPBEXstdData title=0 noWrap>0</TD>
<TD class=SAPBEXstdData noWrap> </TD>
<TD class=SAPBEXstdData noWrap> </TD>
<TD class=SAPBEXstdData noWrap> </TD>
<TD class=SAPBEXstdData title=0 noWrap>0</TD>
<TD class=SAPBEXstdData noWrap> </TD>
<TD class=SAPBEXstdData noWrap> </TD>
<TD class=SAPBEXstdData noWrap> </TD>
<TD class=SAPBEXstdData noWrap> </TD>
<TD class=SAPBEXstdData noWrap>I NEED THIS ONE (9th) of every Data Row</TD>
<TD class=SAPBEXstdData title=0 noWrap>
<DIV class=notiz style="TEXT-ALIGN: left"></DIV></TD></TR>
<TR>
<TD class=SAPBEXstdItem noWrap>G000164</TD>
<TD class=SAPBEXstdItem noWrap>Tag der offenen Tür</TD>...
........
Try and put input in front of your selector (like input[name=TABLE_1] tr), because it may be that jQuery is looking through every element, including spans, divs, h1s, etc...
$('[name=TABLE_1] tr') seems invalid because TABLE or TBODY don't have any NAME attribute (correct me if I'm wrong).
Two different solutions:
If it ain't broke, don't fix it: stay with jQuery 1.4.2. or...
Rewrite the selector so that it selects more efficiently. Start with $('table[name=TABLE_1] tr'), and use a more specific selector in .find() - perhaps use .children() instead of .find()? Would need to see the actual markup for more specific suggestions.
Edit Your markup is horribly invalid. form is not a valid child of table, name is not a valid attribute of table (as pointed out by #Capsule), you're not using nowrap correctly... I recommend that you familiarize yourself with the W3C Validator and go from there.