def nspath_eval(xpath, nsmap):
    """Return an etree friendly xpath.

    This function converts XPath expressions that use prefixes into
    their full namespace. This is the form expected by lxml [1]_.

    Parameters
    ----------
    xpath: str
        The XPath expression to be converted
    nsmap: dict

    Returns
    -------
    str
        The XPath expression using namespaces instead of prefixes.

    References
    ----------
    .. [1] http://lxml.de/tutorial.html#namespaces

    """

    out = []
    for node in xpath.split('/'):
        chunks = node.split(":")
        if len(chunks) == 2:
            prefix, element = node.split(':')
            out.append('{%s}%s' % (nsmap[prefix], element))
        elif len(chunks) == 1:
            out.append(node)
        else:
            raise RuntimeError("Invalid XPath expression: {0}".format(xpath))
    return '/'.join(out)