def get_element_dict(xpath, var_value=None, var_dim=None,
    include_reference_data=False):
    """
    Function to create a D3.js-type dictionary for a nested tree based on an xpath.

    :param xpath: xpath for the element
    :type xpath: str
    :param var_value: value of the element in a reference file
    :type var_value: float
    :param var_dim: dimension of the element in a reference file
    :type var_dim: int
    :param include_reference_data: setting on whether reference data should be include in the path
    :type include_reference_data: bool
    :return: nested dictionary
    :rtype: dict
    """
    xpath_list = xpath.split('/')[1:]
    xpath_list.reverse()
    max_depth = len(xpath_list) - 1
    for idx, element in enumerate(xpath_list):
        if idx == 0:
            if include_reference_data:
                element_dict = dict(name=element, level=max_depth - idx,
                    type='variable', value=var_value, dimension=var_dim)
            else:
                element_dict = dict(name=element, level=max_depth - idx,
                    type='variable')
        elif idx != max_depth:
            element_dict = dict(name=element, level=max_depth - idx, type=
                'variable', children=[element_dict])
        else:
            element_dict = dict(name=element, level=max_depth - idx,
                children=[element_dict])
    return element_dict
