Cypher

// Export TEI-Graph to Standoff-Property-JSON-Format match path=(d:XmlDocument)-[:NE*]->(e:XmlCharacters) where not (e)-[:NE]-> with tail(nodes(path)) as words, d with reduce(s="", x in words| s + x.text ) as allText, d call apoc.path.expandConfig(d,{  relationshipFilter: '(x) where (x)-[:LAST_CHILD_OF*]->(this) and any(x in nodes(p) WHERE x:XmlCharacters) with allText, this, collect(p)[-1] as longest with allText, this, [x in nodes(longest) where x:XmlCharacters] as xmlCharacters with allText, this, apoc.coll.min([x in xmlCharacters | x.startIndex]) as min, apoc.coll.max([x in xmlCharacters | x.endIndex]) as max, apoc.text.join([x in xmlCharacters | x.text], "") as text with allText, { index:id(this), startIndex: min, endIndex: max, text: text, type: this._name, attributes: apoc.map.fromPairs([x in keys(this) WHERE not x starts with "_" | [x, this[x]] ]) } as standoffProperty return {text: allText, properties: collect(standoffProperty)};