Page 1 of 1

Xpath query fails if "all opened files"

Posted: Wed Jun 17, 2015 10:07 pm
by luxlunae
This executes just fine if run individually on any given file:

//mods:relatedItem/mods:titleInfo[(following-sibling::mods:titleInfo)]/mods:title

but if I tell it to run on all opened files (which are all the same kind of xml metadata)

I get this error:

XPath failed du to: Prefix mods has not been declared.

the mods comes from xmlns:mods="http://www.loc.gov/mods/v3 presumably.

If I remove the mods: from the node names the query runs but doesn't work.

Re: Xpath query fails if "all opened files"

Posted: Thu Jun 18, 2015 5:24 pm
by radu_pisoi
The composition of the prefix-namespace mappings used when executing an XPath expression is done by following the next rules:
* the mappings from the XML/XSLT-FO-XQuery/XPath preferences page are added first - see the Default prefix-namespace mappings and the XPath default namespace sections;
* if the XPath execution scope is Current file, then the prefix-namespace mappings are enriched with the ones declared on the root element of the current file.
For more details please go to http://www.oxygenxml.com/doc/versions/1 ... xpath.html
luxlunae wrote:This executes just fine if run individually on any given file:
//mods:relatedItem/mods:titleInfo[(following-sibling::mods:titleInfo)]/mods:title
This works because the namespace for the mods prefix is detected from the current file when the execution scope is Current File.
luxlunae wrote: but if I tell it to run on all opened files (which are all the same kind of xml metadata)
I get this error:
XPath failed du to: Prefix mods has not been declared.
When running an XPath expression over multiple files, the namespace-prefix mappings used by the processor are the ones declared in the Default prefix-namespace mappings table from the XML/XSLT-FO-XQuery/XPath preferences page. So, in your case you have to add a new entry (mods -> http://www.loc.gov/mods/v3) in this table.
luxlunae wrote: the mods comes from xmlns:mods="http://www.loc.gov/mods/v3 presumably.
If I remove the mods: from the node names the query runs but doesn't work.
The XPath default namespace is computed accordingly with the XPath Default Namespace option from the XML/XSLT-FO-XQuery/XPath preferences page. In your case you can switch to 'This Namespace' entry and set its value to http://www.loc.gov/mods/v3.

Re: Xpath query fails if "all opened files"

Posted: Thu Jun 18, 2015 10:04 pm
by luxlunae
It works like magic! Thanks!