Open lloyd opened 13 years ago
Of the options above, I think that :include()
and :exclude()
are fairly comprehensive and semantically sound
decisive. good.
just to mention: iv not given up the topic, im still in pondering mode! I think im more leaning to this sort of functionality in a differnt libray. ie, goiing back to my xpath/xslt comparison
Also check out XQuery since it introduced the idea of modifying the result set over XPath.
Really once you start wanting to change the results you need something that templates the final result, like XSL and XQuery had. In JavaScript/JSON you can obviously use a literal for that. JSONiq shows some good examples of how it could look www.w3.org/2011/.../Documentation-0.1-JSONiq-Article-en-US.pdf
Suggested by @dunkfordyce , implementation discussed here: http://librelist.com/browser//jsonselect/2011/6/3/objects/#b8bb946b3b839bd5894d9f78a5c6fb2fh
What if you want to limit the amount of data that's selected by your selector? A concrete case is when selecting a subset of twitter's api which return HUGE JSON OBJECTS with lots of stuff that YOU PROBABLY DONT CARE ABOUT
The proposal is to add two functions, one which discards items matching a selector, and the other which discards items not matching a selector. Naming is up in the air a bit, here are options:
:only()
and:without()
:include()
and:exclude()
:reduce()
and:remove()
:limit()
and:filter()
These functions take a selector as an argument (like
:has()
), they do not affect the selection algorithm at all, but are applied after elements are selected and modify the return value.for instance, given the document:
both
:root:only(.first,.last)
and:root:remove(.middle)
would return: