Thank you for your answer!
But this solution does not work with one-to-many relationships.
When I run the following script:
let $i := <root>
  <a id = "a1" idref = "b1"> aaa1</a>
  <a id = "a2" idef = "b1">aaa2</a>
  <a id = "a3" idef= "b2"> aaa3</a>
  <a id = "a11" idref = "b2"> aaa11</a>
  <b id = "b1" idref = "a1 a2">bb1</b>
  <b id = "b2" idref = "a3 a11">bb2</b>
</root>
return $i/*[matches(@idref, 'a1')]
BaseX produces the result:
<b id="b1" idref="a1 a2">bb1</b>
<b id="b2" idref="a3 a11">bb2</b>
that is different from: <b id="b1" idref="a1 a2">bb1</b>
 
Besides, my question is about the function idref()? Is it supported?
I find some examples here: http://www.xqueryfunctions.com/xq/fn_idref.html
I have defined DTD, schema, but the result is the same.
BaseX requires the name of the attribute-identifier to contain “id” and the name of the attribute with references to contain ‘idref’. But the function idref() returns result only if the relationship is one-to-one.
I would be grateful if you tell me how to apply the function idref() when the relationship is one-to-many.
Best regards,
Tsvetanka