How can i show descendants of tagged revision excluding the tag? - mercurial

With the command
hg log --rev "descendants(last(tagged()))"
I get a list of all changesets from the last tag including the tagged changeset. How can I exclude the latter?

descendants(children(last(tagged())))
last(tagged()) gives you the tag changeset.
and children returns direct child (or children) of that tagged changeset.
leaving descendants to return all the descendant children of tags child.

Related

How to use XPath preceding-sibling correctly?

I'm having a trouble selecting preceding siblings. Here's the html:
<div>
<h2>Apple</h2>
<div class="row">A</div>
<h2>Banana</h2>
<div class="row">B</div>
<h2>Strawberry</h2>
<div class="row">C</div>
</div>
My XPath: preceding-sibling::h2.
What I want to do: Select every closest previous h2 element for every div.row .
For example, div.row A gives me Apple h2, div.row B gives me Banana h2 and div.row C gives me Strawberry h2.
The problem is my XPath was wrong, it only selected Apple h2 for every div.row. How can I fix this?
The XPath axis, preceding-sibling, contains all preceding sibling nodes of the context node. The XPath, preceding-sibling::h2, selects all h2 sibling elements starting from the context node.
Therefore, if the context node is <div class="row">C</div> element,
/div/div[.="C"]/preceding-sibling::h2
selects
<h2>Apple</h2>
<h2>Banana</h2>
<h2>Strawberry</h2>
Indexing starts nearest the current node, so
/div/div[.="C"]/preceding-sibling::h2[1]
selects just
<h2>Strawberry</h2>
and
/div/div[.="C"]/preceding-sibling::h2[last()]
selects just
<h2>Apple</h2>
The above examples, of course, would also hold true if you obtained the context node programmatically (rather than as /div/div[.="C"] via XPath) and used preceding-sibling::h2[1] or preceding-sibling::h2[last()] relative to the context node in the hosting language/framework (nokogiri).
If you want to select closest preceding sibling - just add index [1]:
preceding-sibling::h2[1]

CSS: Select elements with only one parent matching attribute selector

I'm a bit of a noob to coding so sorry if this is a dumb question, but I'm trying to write a general purpose scraper for getting some product data using the "schema.org/Product" HTML microdata.
However, I came into an issue when testing (on this page in particular where the name was being set as "Electronics" from the Breadcrumbs schema) as there were ancestor elements with different itemtypes/schema.
I first have this variable declared to check if the page has an element using the Product schema microdata.
var productMicrodata = document.querySelector('[itemscope][itemtype="https://schema.org/Product"], [itemscope][itemtype="http://schema.org/Product"]');
I then wanted to select for all elements with the itemprop attribute. e.g.
productMicrodata.querySelectorAll('[itemprop]');
The issue however is that I want to ignore any elements that have other ancestors with different itemtypes/schema attributes, as in this instance the Breadcrumbs and ListItem schema data is still being included.
I figured I would then just be able to do something like this:
productMicrodata.querySelectorAll(':not([itemscope]) [itemprop]');
However this is still returning matches for the child elements having ancestor elements with different itemscope attributes (e.g. breadcrumbs).
I'm sure I'm just missing something super obvious, but any help on how I can achieve only selecting elements that have only the one ancestor with itemtype="http://schema.org/Product" attribute would be much appreciated.
EDIT: For clarification of where the element(s) are that I'm trying to avoid matching with are, here's what the DOM looks like on the example page linked. I'm trying to ignore the elements that have any ancestors with itemtype attributes.
EDIT 2: changed incorrect use of parent to ancestor. Apologies, I am still new to this :|
EDIT 4/SOLUTION: I've found a non-CSS solution for what I'm trying to achieve using the javascript Element.closest() method. e.g.
let productMicrodata = document.querySelectorAll('[itemprop]');
let itemProp = {};
for (let i = 0; i < productMicrodata.length; i++) {
if (productMicrodata[i].closest('[itemtype]').getAttribute('itemtype') === "http://schema.org/Product" || productMicrodata[i].closest('[itemtype]').getAttribute('itemtype') === "https://schema.org/Product") {
itemProp[productMicrodata[i].getAttribute('itemprop')] = productMicrodata[i].textContent;
}
}
console.log(itemProp);
:not([itemscope]) [itemprop] means:
An element with an itemprop attribute and any ancestor with no itemprop ancestor.
So:
<div>
<div itemprop>
<div itemprop> <!-- this one -->
</div>
</div>
</div>
… would match because while the parent element has the attribute, the grandparent does not.
You need to use the child combinator to eliminate elements with matching parent elements:
:not([itemscope]) > [itemprop]
[...] help on how I can achieve only selecting elements that have only
the itemtype="http://schema.org/Product" attribute would be much
appreciated.
Attribute selectors can take explicit values:
[myAttribute="myValue"]
So the syntax for this would be:
var productMicrodata.querySelectorAll('[itemtype="http://schema.org/Product"]');

Creating custom _nested_ html tags using x-tag

I'm attempting to create a custom html tag using Mozilla's http://www.x-tags.org/. I have been able to register a test tag and use it correctly; however, I can't find any good examples of nested tags.
For example:
<parent-tag parent-attribute="parent">
<child-tag child-attribute="child1"/>
<child-tag>child2</child-tag>
</parent-tag>
I can get parent-attribute using 'accessors,' but how do I get child-attribute or value of the second child-tag?
I've seen a couple of hints that inside lifecycle of child nodes, I should reference parent nodes. However, how does that work when a set of tag hierarchy works together to create a result:
<chart-tag width="300", height="300">
<chart-x-axis isVisible="false"/>
<chart-y-axis min="0" max="100"/>
<chart-legend> this is the legend</chart-legend>
</chart-tag>
In order to convert this made-up tag soup into a chart, I need to get all values from all nodes. Do I have to start traversing parent/sibling nodes myself?
I've been able to solve this, although I'm not certain if this is the best way.
In the parent tag, by the time 'inserted' lifecycle is called, all child nodes have been parsed and can be accessed by
xtag.queryChildren(this,'child-node-tag');
Reference to child nodes can be used to traverse its attributes: childnode.attribute1
Note that child tags must also be registered, although there doesn't seem to be a need to 'link' parent and child tags in any direct way. A very simple example is available at https://github.com/falconair/dimple-chart/blob/master/dimple-chart-test.htm (take a look at the code early in the version history, don't know how it will evolve over time).

XPath to select all href's in element

i have a trouble with XPath. I have a HTML page with complicated structure and i want to select ALL href's elements in particular div, regardless of the depth of nesting.
Why next code doesn't work and what can I do to fix?
//*[#id='some_id']//*//a
Matching #href attributes
Select all #href attributes, not all anchor tags.
//*[#id='some_id']//#href
If you only want to match the #href attributes of anchor tags, go for this query, which selects all anchor tags inside that "some_id"-element, and then their #href tags.
//*[#id='some_id']//a/#href
// and the descendant-or-self-axis
I'm not sure what you wanted to achieve with the .//*//a construct. This is an abbreviation for
./descendant-or-self::node()/child::*/descendant-or-self::node()/child::a
so there must be some element in-between. If the anchor tag is directly contained within the #id='some_id'-element, it will not be found, for example for this input:
<div id='some_id'>bar</div>
//*[#id='some_id']//a would have matched this element.
// addresses the entire descendant axis, so this is sufficient:
//*[#id='some_id']//a
Otherwise, you wouldn't get a elements that are immediate descendants of the element addressed with //*[#id='some_id']. (If your environment recognizes id attributes as being IDs, you can also address this element with id('some_id').)
But your problem is likely to be something different. //a usually addresses all a elements in the null namespace. Possibly your a elements aren't in the null namespace but in the XHTML namespace. You could match them like
//*[#id='some_id']//*[local-name()='a' and namespace-uri()='http://www.w3.org/1999/xhtml']
or, if you only have to expect HTML elements anyway
//*[#id='some_id']//*[local-name()='a']
or in XPath 2.0 even simpler
//*[#id='some_id']//*:a
Depending on your environment, you can also register a namespace prefix so that you can do something like
//*[#id='some_id']//html:a
in both XPath 1.0 and 2.0.

Xpath - finding sibiling

I want to find the parent and the sibiling of some nodes in a website (it xpath). My big problem is that I want to find a sibiling of node, with no Id, only by it attribute.
for example:
<a id="nav-europe-3231" class="" href="/EUROPE/" title="Europe News Headlines and Video from CNN.com International">Europe</a>
<a id="nav-asia-1265" class="" href="/ASIA/" title="Asia News Headlines and Video from CNN.com International">Asia</a>
I saw some instruction, like parent::child-node, but it doesn't find the xpath in this way.
How can I find the parents and the sibiling of this node?
In XPath 1 you can find the siblings and parent of the context node via the preceding-sibling:: and following-sibling:: axes (for siblings) and either ../ or theparent::` axe to find the parent.
Note that with axes you must specify a node name after the ::. If you don't know it, you can use the wildcard, *.
See http://www.w3schools.com/xpath/xpath_axes.asp