Look up "attribute value templates". You can embed an XPath expression within curly braces:
<a href="{s:CriminalRecord//d8p1:BinaryReferenceID/d8p1:ID}">
or of course
<a href="{$test}">
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference