Closed gareth-robinson closed 7 years ago
Ok, if it was known that in my example document above, that the document was always in the layout above and the 'root' identifier was always included, then I could obtain the value I need using
var allIdentifiers = doc.queryAll( "ex:identifier @value" );
var rootIdentidier = allIdentifiers[ allIdentifiers.length - 1 ];
See here for the rules regarding order of selection: https://dev.w3.org/2006/webapi/selectors-api2/#first
Or, if you are a human, see here for MDN's statement that it is "depth-first, pre-order" traversal: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
I think the most obvious example of this problem would be when trying to select the @id of the document
Looks like this is a discussion for HTML as well - see here: https://groups.google.com/forum/#!topic/jsmentors/SYnpRji5TZU
Consensus seems to be that use of the child combinator is the solution for now. I suggest that we should also implement that for this case.
I've added child combinators into my fork. Pull request is https://github.com/goofballLogic/ld-query/pull/14
Given a document that includes
what should we expect query( "ex:identifier" ) to return? The "annotation1_identifier" or "12345"? At the moment it is "annotation1_identifier", the first entry that matches the query.
If this was html e.g.
then document.querySelector(".a").innerHTML returns "test1", so that matches the functionality of the ld-query 'query' method
To get 'test2' in the html we'd need to use document.querySelector( "body > .a" )
Does ld-query need changed to find the 'simplest' match for a path? Or does it need to include additional operator types like '>'? Or can the 'expand' method that it uses internally be externalised, so that developers can process json manually (though that's a bit of a fudge)?