3

I use the following to extract two values using xidel -e.

  • '//input[@name="qid"]/@value[1]'
  • "//span[@id='trueFinalResultCount']"

But I'd like to put the two results into a TSV format.

result1<TAB>result2

Could anybody show me how to combine the above two expressions? (I tried the following. But it doesn't work.)

'join((//input[@name="qid"]/@value[1], //span[@id='trueFinalResultCount'][1]), x:cps(9))'

Joe Wicentowski
  • 5,159
  • 16
  • 26
user1424739
  • 11,937
  • 17
  • 63
  • 152
  • 1
    Try `string-join( ($x, $y), ' ')` – Joe Wicentowski Nov 10 '19 at 04:15
  • Could you test the solution with `xidel`? I tried `'string-join((//input[@name="qid"]/@value[1], //span[@id='trueFinalResultCount'][1]), " ")'`. But I just get the first value. – user1424739 Nov 10 '19 at 04:50
  • Could you share your source? Also please fix your quoting. `'function("string")'` is for Unix, while `"function('string')"` is for Windows. – Reino Nov 10 '19 at 11:57
  • I don't have your data, but this works: `xidel https://google.com --xquery 'string-join(//a ! string-join(((./string(), "¡Untitled!")[. ne ""][1], @href), " "), " ")'`. This uses standard XQuery 3 to create a TSV file: one row for each link on the Google homepage, and two columns per row (separated by tab): title and URL. If you provide a URL with your data, I would be happy to provide an answer specific to your question. – Joe Wicentowski Nov 11 '19 at 23:07
  • I agree with Reino - your use of quotes is likely the cause of your problem. In my sample (used on macOS), notice how a single pair of single quotes (`'`) surrounds the entire query body, and inside the query body, only double quotes (`"`) are used. – Joe Wicentowski Nov 12 '19 at 02:23
  • @joewiz Your example query could be simplified to `--xquery '//a ! join(((text(),"¡Untitled!")[1],@href)," ")'`, or `-e '[...],x:cps(9))'`. – Reino Nov 13 '19 at 00:34
  • True. I was sticking with pure XQuery. – Joe Wicentowski Nov 13 '19 at 01:13
  • Also, there’s no guarantee that the a elements have only one child text node. – Joe Wicentowski Nov 13 '19 at 01:15

1 Answers1

2

string-join( ($x, $y), ' ') and replace ' ' with "tab-key pressed here"

example:

xidel URL --xpath 'string-join((somepath1, somepath2)," ")'

it results into TSV

P....
  • 17,421
  • 2
  • 32
  • 52
masgandhul
  • 21
  • 3