Xpath query fails if "all opened files"

Issues related to W3C XQuery.
luxlunae
Posts: 26

Xpath query fails if "all opened files"

Wed Jun 17, 2015 10:07 pm

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.
radu_pisoi
Posts: 302
Location: Craiova

Re: Xpath query fails if "all opened files"

Thu Jun 18, 2015 5:24 pm

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/17.0/ug-editor/#topics/preferences-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.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
luxlunae
Posts: 26

Re: Xpath query fails if "all opened files"

Thu Jun 18, 2015 10:04 pm

It works like magic! Thanks!

Return to “XQuery”

Who is online

Users browsing this forum: No registered users and 0 guests