I'm looking for the right xpath syntax to get a specific parent of an element.
Example:
root
|- div
| |
| |----??? ---|
| | |-a [class=1]
| | |- text[ A TEXT I DON'T WANT]
| |
| |
| |
| |-text[THE TEXT]
|
|-div
| |-text[THE TEXT I DON'T WANT]
|
|-div
| |-text[THE TEXT I DON'T WANT]
I want to get the text "THE TEXT" but the one that contains a [class=1] inside the same div. Something like this:
//div//a[#class=1]/text[contains(.,'A TEXT')]/parent::*/parent::*.... <till div element> /text
Given the XML
<?xml version="1.0"?>
<root>
<foo id="id1">
<foo id="i2">
<baz/>
</foo>
</foo>
</root>
You can find the nearest ancestor foo element from baz using the XPath expression:
//baz/ancestor::foo[1]
Which will select the foo element node of id "i2".
So in your example (if I understand right) once you have got the "a" element you want, you can get "back up" the tree to the nearest ancestor div by appending "/ancestor::div[1]" to your expression.
Use:
/root/div[.//a[#class='1']]/text()
This selects any text node that is a child of any a element that has a class attribute with value '1' and that (the a element) is a descendent of any div element that is a child of the top element named root.
Related
I want to put some charts on Superset dashboard. The layout I want is like this:
____________________
| | |
| | B |
| A |_________|
| | |
| | C |
|__________|_________|
A is a chart with some main info and B and C are details of it. The problem is if I put B as it is then C cannot be put below B and will form a completely new row. I tried to achieve this form with an empty row or column or separator and no luck yet.
Try following these steps and see if it works:
Add an empty row
Add two empty columns in it
Add two empty rows on the right column
Add charts into desired cells.
Adjust width and height.
I have this table:
[width="10%", cols="^", options="header"]
|===
| header
| one
| two
| three
| four
|===
Which renders as:
In order to get to none-striped:
I do this:
[width="10%", cols="^", options="header"]
|===
| Header
| one
{set:cellbgcolor:white}| two
| three
| four
|===
{set:cellbgcolor!}
But the disadvantage of this is clear (verbosity, forcing specific color, ...), not to state that it doesn't work in other AsciiDoctor variants (e.g. PDF)
I am aware of issue #1365, but it's very new, and only implemented in the ruby variant of AsciiDoctor, not in its JS variant (with which most of the WYSIWYG editors work).
Long story short - is there anyway to achieve it in present state?
Did you try 'stripes=none' (manual)?
[cols="2,4,2,4,2", stripes=none, grid=none, frame=none]
|===
| ^.>| +++_____________________+++ | ^.>| +++_____________________+++ |
| ^.<| Unterschrift | ^.<| Unterschrift |
|===
I have a tree of nodes which are quite frankly a mess.
|-...
|-cat
\-dog
|- dog *
| |- chicken
| | \- cat !
| \- cat !
| \- cat !
| \- dog
| |- cat
| \- ...
|- cat
|- dog
| \- cat
\- ...
Given that I've selected the asterisked 'dog' node, how can I select only those cats for whom it is the most recent 'dog' ancestor (i.e. those that have an exclamation mark)
Equivalently, how can I get only those cat descendants of the node that can be reached without traversing another dog node?
I'm working in lxml and currently have a bad solution involving disconnecting the graphs by drop_tree()-ing all dog nodes.
You could use EXSLT's set extensions: http://www.exslt.org/set/. They're available in lxml using namespaces={"set": "http://exslt.org/sets"} in your XPath expressions.
You could then do something like
asteriskeddog.xpath("set:difference(.//cat, .//dog/cat)",
namespaces={"set": "http://exslt.org/sets"})
meaning "all cat elements under the current node, except those under a dog element under the current node. I've used that trick in some microdata parsing with nested itemscope and itemprop elements
I am using a scenario table (multiline step arguments) to check some data from a screen using cucumber, using the in built .diff! method on the Cucumber AST table.
I would like to check the content matches against regular expressions.
Scenario: One
Then the table appears as:
| One | Two | Three |
| /\d+/ | /\d+/ | /\d+/ |
The actual table could look something like
| One | Two | Three |
| 123 | 456 | 789 |
which this scenario is translated to "as long as there are some digits, I don't care"
An example step implementation that fails:
Then /^the table appears as:$/ do |expected_table|
actual_table = [['One','Two', 'Three'],['123', '456', '789']]
expected_table.diff! actual_table
end
Error:
Then the table appears as: # features/step_definitions/my_steps.rb:230
| One | Two | Three |
| /\\d+/ | /\\d+/ | /\\d+/ |
| 123 | 456 | 789 |
Tables were not identical (Cucumber::Ast::Table::Different)
I have tried using step transforms to transform the cells into regular expressions, but they still aren't identical.
Transform code:
expected_table.raw[0].each do |column|
expected_table.map_column! column do |cell|
if cell.respond_to? :start_with?
if cell.start_with? "/"
cell.to_regexp
else
cell
end
else
cell
end
end
end
which provides the eror:
Then the table appears as: # features/step_definitions/my_steps.rb:228
| One | Two | Three |
| (?-mix:\\d+) | (?-mix:\\d+) | (?-mix:\\d+) |
| 123 | 456 | 789 |
Tables were not identical (Cucumber::Ast::Table::Different)
Any ideas? I am stuck.
Using regular expressions in a scenario is almost certainly the wrong approach. Cucumber features are intended to be read and understood by business-focussed stakeholders.
How about writing the step at a higher level, such as as:
Then the first three columns of the table should contain a digit
There is no way to do it without writing your own implementation of diff! method from Ast::Table. Take a look into cucumber/lib/ast/table.rb. Internally it uses diff-lcs library to do an actual comparison which doesn't support regex match.
It seems that you want to write this in a way that provides the cool diff output. Otherwise, I'd look at writing this such that you simply check the rows. It won't be as pretty, and it won't get you the diff of the entire table, but it's something.
Then /^the table appears as:$/ do |expected_table|
actual_table = [['One','Two', 'Three'],['123', '456', '789']]
expected_table.raw.each_with_index { |row, y|
row.each_with_index { |cell, x|
actual_table[x][y].should == cell
}
}
end
I have a label and a field as in the follwing layout.
________________
| _____ |
| | | |
| |Label| |
| |_____| |
| |
| ____________ |->Outer fixedframe
| | _______ | |
| | | | | |
| | |field| | |
| | |_____| | |
| |__>_______| |
| | |
| -->Inner |
| Horizontally expanding repeating frame
|______________|
I would like to center align the label with respect to the field in the inner repeating frame. For example,
If the repeating frame generates 5 fields, the label needs to be right above the 3rd field.
Is this possible using oracle reports or any alternate layouts?. Any help would be much appreciated
I just got this working with a quick mock-up and here is how I did it:
1) Select the "Anchor" tool from the tool palette and anchor the bottom middle "outline square" (I'm not sure what the technical term for those are but the grab-points on an object where you can resize them) from the label object and connect it to the top middle "outline square" of the horizontal repeating frame.
2) [Optional] Click on the anchor line and check the properties to make sure the Child Edge Type is set to "Bottom", the Child Edge Percent is "50", the Parent Edge Type is "Top", and the Parent Edge Percent is "50".
3) Click on the label and set the Keep With Anchoring Object property to "Yes".
4) Make sure your label is centered over the repeating frame in the Paper Layout view. I noticed that if it is off-centered to start with it will be off-centered by the same amount when run. I ended up making the label the same width as the repeating frame it was over and then set both to a Horizontal Elasticity of "Variable".
I ran this with 5 horizontally repeated objects and then I added a 6th to verify it remained centered and both worked.
Hope that helps and that I didn't miss a step. I'll save the mock-up in case it needs further steps or explanation.