Skip to content

Commit

Permalink
Allow the return of combined IDs for multi-id xpaths.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
luciansmith committed Oct 9, 2024
1 parent 49e8a80 commit 92f1cea
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion biosimulators_utils/sedml/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down

0 comments on commit 92f1cea

Please sign in to comment.