@@ -509,7 +509,7 @@ def apply_changes_to_xml_model(model, model_etree, sed_doc=None, working_dir=Non
509509
510510 elif isinstance (change , ModelAttributeChange ):
511511 xpath_captures = regex .split (r"[\[|\]]" , change .target )
512- if len (xpath_captures ) != 3 or "@" not in xpath_captures [1 ] or xpath_captures [ 2 ] != "" :
512+ if len (xpath_captures ) < 3 or "/ @" in xpath_captures [- 1 ] :
513513 # Old method for ModelAttributeChange
514514 # get object to change
515515 obj_xpath , sep , attr = change .target .rpartition ('/@' )
@@ -534,18 +534,22 @@ def apply_changes_to_xml_model(model, model_etree, sed_doc=None, working_dir=Non
534534 obj .set (attr , change .new_value )
535535 else :
536536 # New Method for ModelAttributeChange
537- xml_target_captures = regex .split (r"[\@|=]" , xpath_captures [1 ])
537+ xml_target_captures = regex .split (r"[\@|=]" , xpath_captures [- 2 ])
538538 xml_target_captures [2 ] = xml_target_captures [2 ][1 :- 1 ]
539- _ , target_type , target_value = tuple (xml_target_captures )
539+ # _, target_type, target_value = tuple(xml_target_captures)
540540 xml_model_element = eval_xpath (model_etree , change .target , change .target_namespaces )
541541 if validate_unique_xml_targets and len (xml_model_element ) != 1 :
542542 raise ValueError (f'xpath { change .target } must match a single object' )
543543 xpath_tiers = [elem for elem in regex .split ("/" , xpath_captures [0 ]) if ":" in elem ]
544544 if len (xpath_tiers ) == 0 :
545545 raise ValueError ("Unexpected number of tokens in model element xpath" )
546546 element_type = regex .split (":" , xpath_tiers [- 1 ])
547+ second_element_type = None if len (xpath_captures ) != 5 \
548+ else regex .split (":" ,
549+ [elem for elem in regex .split ("/" , xpath_captures [2 ]) if ":" in elem ][- 1 ])
547550
548551 namespace_prefix , type_suffix = tuple (element_type )
552+ _ , second_type_suffix = tuple (second_element_type ) if second_element_type else (None , None )
549553 if change .target_namespaces .get (namespace_prefix ) is None :
550554 raise ValueError (f'No namespace is defined with prefix `{ namespace_prefix } `' )
551555 # change value
@@ -556,6 +560,9 @@ def apply_changes_to_xml_model(model, model_etree, sed_doc=None, working_dir=Non
556560 attribute .set ("size" , change .new_value )
557561 elif type_suffix == "parameter" and attribute .get ("value" ) is not None :
558562 attribute .set ("value" , change .new_value )
563+ elif (type_suffix == "reaction" and second_type_suffix == "parameter"
564+ and attribute .get ("value" ) is not None ): # Reaction parameter change
565+ attribute .set ("value" , change .new_value )
559566 else :
560567 change .model = model
561568 non_xml_changes .append (change )
0 commit comments