find-element(Text,[tag(Text,D1)|R],[tag(Text,D1)|Q]):- !, find-element(Text,R,Q). find-element(Text,[tag(_,D1)|R],Q):-find-element(Text,D1,A),find-element(Text,R,B),!, append(A,B,Q). find-element(Text,[_|R],Q):-find-element(Text,R,Q). find-element(_,[],[]). where(Attb,Op,Val,A,B):-find-element(Attb,A,C),where2(Attb,Op,Val,C,B). where2(Attb,Op,Val,[tag(Attb,V2)|S2],[tag(Attb,V2)|B]):-condition(V2,Op,Val),!, where(Attb,Op,Val,S2,B). where2(Attb,Op,Val,[_|S2],B):- where(Attb,Op,Val,S2,B). where2(_,_,_,[],[]). condition(A,eq,A). condition(_,*,_). xml([tag(book,b1),tag(paper,p1),tag(book,b2)]). xml([tag(books,[tag(book,b1),tag(documents,[tag(paper,p3),tag(book,a22)]),tag(book,a22)])]).