From 92f1ceaedb804b3643042d6130c2c9284a2fc2d6 Mon Sep 17 00:00:00 2001 From: Lucian Smith Date: Wed, 9 Oct 2024 14:52:21 -0700 Subject: [PATCH] Allow the return of combined IDs for multi-id xpaths. This is so that an xpath for an SBML local parameter like /sbml:sbml/sbml:model/sbml:listOfReactions/sbml:reaction[@id='J0']/sbml:kineticLaw/sbml:listOfParameters/sbml:parameter[@id='n'] can return J0.n or J0_n instead of just 'n'. Backwards-compatible, so that existing code doesn't break. --- biosimulators_utils/sedml/validation.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/biosimulators_utils/sedml/validation.py b/biosimulators_utils/sedml/validation.py index fdb4a5ce..11a0619b 100644 --- a/biosimulators_utils/sedml/validation.py +++ b/biosimulators_utils/sedml/validation.py @@ -1715,7 +1715,7 @@ def validate_target(target, namespaces, context, language, model_id, model_etree return errors, warnings -def validate_target_xpaths(targets, model_etree, attr='id'): +def validate_target_xpaths(targets, model_etree, attr='id', separator=None): """ Validate that the target of each model change or variable matches one object in an XML-encoded model and, optionally, return the value of one of its attributes @@ -1736,6 +1736,17 @@ def validate_target_xpaths(targets, model_etree, attr='id'): x_path, _, _ = x_path.rpartition('/@') x_path_attrs[target.target] = validate_xpaths_ref_to_unique_objects( model_etree, [x_path], target.target_namespaces, attr=attr)[x_path] + if separator is None: + return x_path_attrs + for xpath in x_path_attrs: + xpath_list = xpath.split("@" + attr + "=") + if len(xpath_list) < 3: + continue + combined_id = "" + for i in range(1, len(xpath_list)-1): + combined_id = combined_id + xpath_list[i].split(']')[0][1:-1] + separator + x_path_attrs[xpath] = combined_id + x_path_attrs[xpath] + return x_path_attrs