benibela / xidel

Command line tool to download and extract data from HTML/XML pages or JSON-APIs, using CSS, XPath 3.0, XQuery 3.0, JSONiq or pattern matching. It can also create new or transformed XML/HTML/JSON documents.
http://www.videlibri.de/xidel.html
GNU General Public License v3.0
674 stars 42 forks source link

documentation for syntax to extract two or more fields from same "record" ? #108

Closed mfioretti closed 6 months ago

mfioretti commented 1 year ago

Greetings,

I am learning Xidel 0.9.8 on Ubuntu. My issue is that I have looked into the documentation, but as far as I can tell it gives no clue (none I recognize, at least) to do this.

I have a JSON file with records that have, among others, id and title fields, eg:

#> jq '.' test.json  | cut -c1-100 | more
[
  {
    "id": 42,
    "title": "Software is eating the world",

I want to extract with Xidel those two values, producing output lines like this:

ARTICLE: 42 ==> Software is eating the world

or at least like this:

42 ==> Software is eating the world

and I can't find, or recognize, the right syntax to use for what seems a general, very common need to me. The closest I have come to what I want is this:

xidel test.json -e 'for $t in $json/title return string-join(("$t/../id", $t), " ==> ")'

which produces lines like these:

$t/../id ==> Software is eating the world

what is the right way to refer to the id value of the current record???

Thanks!

Reino17 commented 1 year ago

Please see the mailinglist for my reply.