I have a task. I must find shortest path between two nodes in XML using BFS. The XML is 'Romeo & Juliet' (you can find it here: [enter link description here](http://www.ibiblio.org/xml/examples/shakespeare/r_and_j.xml "here")).

I must find shortest paths between Juliet and others speakers. Nodes in graph should be speakers, edges - speech in which two speakers appear together. For example: if Juliet talk with X, distance will be 1. But if Juliet talk with X (but not with Y) and X talk with Y, distance is 2.

The result should looks like that (it's only example):

```
<speaker name="Romeo"><distance>1</distance></speaker>
<speaker name="Tybalt"><distance>3</distance></speaker>
<speaker name="Benvolio"><distance>2</distance></speaker>
...

```

I prepare same code, but i don't have idea on BFS:

```
declare function local:BFS($queue,$speakers,$visited,$step)
{
  let $u :=
    for $i in $queue
        for $w in local:neighbour($i)
          (..)

  return ($u)
};

declare function local:neighbour($person as xs:string)
{
let $file := "r_and_j.xml"

let $speakers :=
  distinct-values(doc($file)/PLAY/ACT/SCENE/SPEECH/SPEAKER)

let $sp-query := 

              for $y in $speakers

                where not($person=$y)
                return if(doc($file)/PLAY/ACT/SCENE[SPEECH[SPEAKER=$person] and SPEECH[SPEAKER=$y]])
                       then
                       $y
                       else ()

return $sp-query
};

```

Function 'neighbour' return nodes from neighbourhood (speakers who talk with person which is get from parametr).