Need help in the below code

current code:

let check_domain_existence doc host_name =
let xpathctx = Xml.xpath_new_context doc in
let xpath_string = xpath_string xpathctx in

let obj = Xml.xpath_eval_expression xpathctx
“/responses/response/output/vm” in
let nr_nodes = Xml.xpathobj_nr_nodes obj in
if nr_nodes > 0 then
j=0 in
for i = 0 to nr_nodes-1 do
let node = Xml.xpathobj_node obj i in
Xml.xpathctx_set_current_context xpathctx node;
let domain_name =
match xpath_string “name” with
| None -> “”
| Some sname -> (string_trim sname)

    if domain_name = host_name then
      error Vm_name_already_exists (f_"a domain with the same name %s has already exist in the system") domain_name;


since its throwing error Vm_name_already_exists i want to make it as host_name ^ string_of_int i+1
update host_name by concating with integer i and again check if the host name already exist, if exist it should again increment

It seems unclear what you want to do with your code to me, but maybe you would need a function that increment each time you call it:

let i = ref 0 in
let iterator () = i:=(!i+1); !i