def METHOD_NAME(material: bpy.types.Material, name: str, xml_path: str, copy_textures: bool):
    """ Create RPR material at current material slot using xml.
    Nodes tree is cleaned if present, new created otherwise.
    New output node added if no output found.
    Change Blender material name to material library name.
    Copy textures locally if requested."""
    def clean_material_tree():
        """ Remove every node from material tree except for output """
        log("Cleaning material nodes tree")
        material.node_tree.nodes.clear()
    def create_material() -> bpy.types.Material:
        """ Create new material and assign to current empty material slot, create slot if none found """
        if not bpy.context.object.material_slots.keys():
            bpy.ops.object.material_slot_add()
        # 2. create material for it
        new_material = bpy.data.materials.new(name=name)
        # 3. assign material to material slot
        bpy.context.object.material_slots[bpy.context.object.active_material_index].material = new_material
        new_material.use_nodes = True
        return new_material
    def create_output_node() -> bpy.types.ShaderNode:
        """ Create and return new output node """
        output_node = material.node_tree.nodes.new('ShaderNodeOutputMaterial')
        log("New output node is {}".format(output_node))
        return output_node
    if not material:
        log("No material tree found, creating new material")
        material = create_material()
    else:
        material.name = name
    # overwrite existing nodes tree
    clean_material_tree()
    output = create_output_node()
    root_folder = rpr_material_library.path
    material_folder = os.path.dirname(xml_path)
    # create images loader
    image_loader = MaterialImageLoader(root_folder, material_folder, copy_textures)
    # create material by xml
    closure = compile_material_from_xml(xml_path, material.node_tree, image_loader)
    # Link closure to output node
    if closure:
        log("Linking closure {} to active output {}".format(closure, output))
        material.node_tree.links.new(closure.outputs[0], output.inputs[0])