Xquery to find/replace

Issues related to W3C XQuery.
luxlunae
Posts: 26
Joined: Wed Jun 17, 2015 10:01 pm

Xquery to find/replace

Post by luxlunae »

Code: Select all

//mods:displayForm[text()[contains(.,'Trust')]]/ancestor::mods:name/@type 
This code identifies all of the attributes I want to change, but how do I actually replace the value using xpath/xquery?
alex_jitianu
Posts: 1008
Joined: Wed Nov 16, 2005 11:11 am

Re: Xquery to find/replace

Post by alex_jitianu »

Hi,

You need XQuery Update for that:

Code: Select all


let $d := doc('file://path.to.file/file.xml')

for $attr in $d//mods:displayForm[text()[contains(.,'Trust')]]/ancestor::mods:name/@type
return replace value of node $attr with "changed"
What's worth mentioning is that:
- XQuery Update works only on documents loaded using the doc() function
- you have to use Saxon EE and to enable the XQuery Update support (inside Preferences, on page XML / XSLT-FO-XQuery / XQuery / Saxon-HE/PE/EE)

Best regards,
Alex
luxlunae
Posts: 26
Joined: Wed Jun 17, 2015 10:01 pm

Re: Xquery to find/replace

Post by luxlunae »

Can you load a project using the doc function?
alex_jitianu
Posts: 1008
Joined: Wed Nov 16, 2005 11:11 am

Re: Xquery to find/replace

Post by alex_jitianu »

Hello,

An Oxygen project? No, but you can use the collection() function. You can use it to load files from a directory and you can load a collection using a catalog file.

Best regards,
Alex
luxlunae
Posts: 26
Joined: Wed Jun 17, 2015 10:01 pm

Re: Xquery to find/replace

Post by luxlunae »

Is there a way to use my current project to generate a collection file? An export that I'm not seeing?
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Xquery to find/replace

Post by adrian »

Hi,

I'm afraid you can't generate a collection over the project.
Is this still in relation to the XQuery Update?
If you need to apply the same XQuery Update on multiple (or all) files from your project, you can create a scenario of type XML Transformation with XQuery use Saxon-EE as the transformer and apply it in the root of the project. In practice this will apply the scenario in turn on each of the files from the project.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply