I have 2 xml documents that I need to reference in a nested FLWOR statement.
MJH source.xml
<data-set>
<record>
<table>CONTACT</table>
<column>AGGREGATE_REPORT</column>
<change>Dropped</change>
<logic>Related to agCenter</logic>
</record>
<record>
<table>QNR_DESIGN_TEMPLATE</table>
<column>LOGO1</column>
<change>Dropped</change>
<logic>Related to agCenter</logic>
</record>
</data-set>
This is the outer document and I need to extract the 'table' and 'column' values per row.
MVReport - a collection of report documents that contain SQL statements.
....
<xml-property name="queryText"><![CDATA[select v.*
from poi_visit_details_v v
where v.site_id=?
and v.std_code_id in ('15', 'TelephoneMonitoringVisit')
and to_char(v.actual_visit_date, 'yyyy-mm-dd') = substr(?, 0, 10)
and (reports_access_pk.site_access(v.SITE_ID, ?) = 'Y'
or reports_access_pk.superuser_access(?) = 'Y')
]]></xml-property>
<xml-property name="queryText"><![CDATA[select v.*
from poi_visit_details_v v
where v.site_id=?
and v.std_code_id in ('15', 'TelephoneMonitoringVisit')
and to_char(v.actual_visit_date, 'yyyy-mm-dd') = substr(?, 0, 10)
and (reports_access_pk.site_access(v.SITE_ID, ?) = 'Y'
or reports_access_pk.superuser_access(?) = 'Y')
]]></xml-property>
....
This collection is the inner loop where I need to find all SQL statements that contain the word "select" and the 'table', 'column' values returned from the outer loop.
Here is my xquery.
The issue I have is how to reference the outer 'table','column' values in the inner loop's "where ... and ..." clauses?
for $target in doc("H:\MJH source.xml")/data-set/record
let $tTable := $target/table
let $tColumn := $target/column
for $sql in collection("MVReport") //*:xml-property[@name = "queryText"]
where $sql contains text "select"
and $sql contains $tTable
and $sql contains $tColumn
let $report := base-uri()
return <report><name>{$sql/base-uri()}</name><sql>{$sql}</sql></report>
Thanks for your help.