Finished the first pass of the dynamic 'related videos' sidebar, which displays a random list videos related to the one the user is currently watching. The code is contained within a findRelatedVideos() function to keep the player.php page decently clean. The function is fully documented and fairly simple to use. Though the function is currently displaying videos based on the <nationality> element within the <person> element, it can switch to any other element value within <person> simply by changing the function arguments.
Here's the function doc verbatim:
* Retrieves a list of videos related to $id based on the contents of $field. * The field - for example, 'nationality' or 'residence' - should be within the * <person> element in the video XML file. The default number of videos returned * is 5, but can be configured with the optional $options array. If the number * of related videos is greater than the number of videos to be returned, then * they're chosen randomly. * * The videos are transformed into <li> elements in includes/xslt/related.xslt. * * Due to the structure of the system, the eXist $db object and the results of * the XML query must also be passed. * * The function returns an associative array: * - videos: the formatted video <li> elements, transformed via XSLT * - field: the value of $field * * @param string $id Video ID * @param object $db DB object * @param mixed $xmlResult Result of query from player.php * @param string $field Name of related field within <person> * @param array $options Optional settings OPTIONAL * @return array An array with the videos and the value of $field * @author Jamie Nay * @date 2011-01-31 */