0

Apologies for the poor explanation, as I'm no code expert.

Im extracting a piece of information which is layd out in tables such as this: enter image description here

I need to extract each table for example from Consumer buy-to-let Business table i need the following: Consumer buy-to-let arranger,Consumer buy-to-let advisor

My current XPath which extracts this information but without a comma looks like this:

//*/text()[normalize-space(.)='Consumer buy-to-let Business']/parent::*/parent::*/p

Output:

Consumer buy-to-let arrangerConsumer buy-to-let advisor

I'm struggling to find out how to add the comma as a separator.

Tomas
  • 33
  • 4

1 Answers1

1

Wrapped for legibility:

string-join(
    //text()[normalize-space(.)='Consumer buy-to-let Business']/ancestor::*[2]/p, ','
)

See: fn:string-join.

Note that

  • /parent::*/parent::* is shorter when written as /ancestor::*[2]
  • text nodes must always be children of an element, so //*/text() is the same as //text()

Related reading: Is it possible to apply normalize-space to all nodes XPath expression finds?

Community
  • 1
  • 1
Tomalak
  • 332,285
  • 67
  • 532
  • 628
  • Unfortunately it didn't work for me, i've typed it as : string-join(//text()[normalize-space(.)='Consumer buy-to-let Business']/ancestor::*[2]/p,',') Im using import.io to test, but it doesn't bring up any results. I do only have one line to enter the XPath – Tomas Aug 17 '16 at 21:14
  • The relevant portion of my answer is `string-join(someNodes, 'separator')`. If my path does not return anything, use yours. If that does not work, make a cross-check using `string-join(('foo', 'bar'), '.')`. If *that* does not return `'foo.bar'` then there is something wrong with the way your application evaluates XPath expressions. – Tomalak Aug 17 '16 at 21:19