Closed zpimp closed 4 years ago
concat is only for single values
For a sequence of values you need to use string-join (with just one parameter)
Benito is right of course, but from what I understand you don't want to simply string-join the span values, you want to interleave them:
xidel -s t2.htm -e "//span/text()"
33
234
44
345
5678
xidel -s t2.htm -e "//span/text() ! normalize-space(.)"
33
234
44
345
5678
xidel -s t2.htm -e "(//span/text() ! normalize-space(.))[.]"
33
234
44
345
5678
xidel -s t2.htm -e "//span/div"
kg
m
kg
m
l
xidel -s t2.htm --xquery "
let $a:=//span/div
for $x at $i in (//span/text() ! normalize-space(.))[.]
return
concat($x,'|',$a[$i])
"
33|kg
234|m
44|kg
345|m
5678|l
or
xidel -s t2.htm --xquery "
for $x at $i in //span/div
let $a:=(//span/text() ! normalize-space(.))[.]
return
concat($a[$i],'|',$x)
"
33|kg
234|m
44|kg
345|m
5678|l
Just figured that assigning //span/div
to a variable isn't really necessary, because //span/div
already contains a sequence:
xidel -s t2.htm --xquery "
for $x at $i in (//span/text() ! normalize-space(.))[.]
return
concat($x,'|',(//span/div)[$i])
"
33|kg
234|m
44|kg
345|m
5678|l
Benito is right of course, but from what I understand you don't want to simply string-join the span values, you want to interleave them:
of course. the report is so long, I only skimmed it
Just figured that assigning //span/div to a variable isn't really necessary, because //span/div already contains a sequence:
it is better to use the variable method. let variables are very fast and //
is very slow
You could also interleave with tumbling window
xidel -s t2.htm --xquery '
for tumbling window $w in //span/(text()|div)!normalize-space()[.]
start at $i when true()
end at $j when $i ne $j
return string-join($w, "|")
'
You could also interleave with tumbling window
Wait, what?! :D Where's that coming from? I can't find anything about it.
Btw, are there any differences between //span/(text()|div)
and //span/(text(),div)
?
You could also interleave with tumbling window
Wait, what?! :D Where's that coming from? I can't find anything about it.
It is the XQuery 3 window clause
Btw, are there any differences between
//span/(text()|div)
That sorts the output in document order, i.e. all interleaved here
and
//span/(text(),div)
?
That sorts the output with all text first and then all div
i got 2 separate selects working but concat of those doesent there are more of the first outer div, this is the node that repeats html/body/div but i only left one for simplicity i understand it may be a xpath limitation,
what can i do? i read somewhere xidel supports some kind of script for/foreach iterating over nodes? but i cant find it
or transforming the children in sibling, is this even possible, would css selectors be easier? or xquery?
any help is greatly appreciated
this is the html
this is the desired output
xidel t2.html -e "html/body/div/span/text()"
xidel t2.html -e "html/body/div/span/div/text()"
but xidel t2.html -e "html/body/div/concat(span/text(),'|',span/div/text())"
thank you for your help