问题
How can a remove the literals from the return in employee.../employee and manager.../manager so I can delete employee.../employee and manager.../manager. I want the result to display without the employee and manager in the resulting xml.
<results>
{
for $depen in doc("../company/dependent.xml")//dependent
where $depen/dependent_name=*
return
<row>
<dependent name="{$depen/dependent_name}"/>
{
for $emp in doc("../company/employee.xml")//employee[ssn = $depen/essn ]
return
<employee>
<emp fname="{$emp/fname}" lname="{$emp/lname}"/>
{
for $man in doc("../company/employee.xml")//employee[ssn = $emp/superssn ]
return
<mgr fname="{$man/fname}" lname="{$man/lname}"/>
}
</employee>
}
</row>
}
</results>
回答1:
I think you want
<results>
{
for $depen in doc("../company/dependent.xml")//dependent
where $depen/dependent_name=*
return
<row>
<dependent name="{$depen/dependent_name}"/>
{
for $emp in doc("../company/employee.xml")//employee[ssn = $depen/essn ]
return
(
<emp fname="{$emp/fname}" lname="{$emp/lname}"/>,
for $man in doc("../company/employee.xml")//employee[ssn = $emp/superssn ]
return
<mgr fname="{$man/fname}" lname="{$man/lname}"/>
)
}
</row>
}
</results>
in terms of the syntax, I am not sure the comparison $depen/dependent_name=* makes any sense without having a context.
来源:https://stackoverflow.com/questions/58718807/how-would-you-remove-all-literals-from-this-xquery