I am using xquery to search and compare values from a source xml file against an svg file. Here is my xquery:

for $xval in $figure/graphic/sheet/doc(@svgsrc)//*[text() = $rdi/text()],   
    $line in $figure/graphic/sheet/doc(@svgsrc)/svg/line   
where functx:between-inclusive($xval/@x, $line/@x2, $line/@x1) 
return $line/@class

The above xquery works well when all $xval (svg text element) have the @x attribute. However, some $xval have the @transform="matrix(0 -1 1 0 248.402 118.972)" wherein the x value is the 5th position of the matrix.

Is it possible for the first argument of functx:between-inclusive to come from 2 different attribute values?

Is there a better way?

1

There are 1 best solutions below

3
On BEST ANSWER

From your question it sounds like you want to always select the @transform value when @x isn't available:

for $xval in $figure/graphic/sheet/doc(@svgsrc)//*[text() = $rdi/text()],   
    $line in $figure/graphic/sheet/doc(@svgsrc)/svg/line   
let $x := ($xval/@x, xs:double(tokenize($xval/@transform, '\s')[5]))[1]
where functx:between-inclusive($x, $line/@x2, $line/@x1) 
return $line/@class

This will assign to variable $x a sequence of both values, selecting only the first one. If the first value is empty, the second is selected because it will be the first value in a 1-item sequence.