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 » Wed Aug 05, 2015 11:26 pm

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: 682
Joined: Wed Nov 16, 2005 11:11 am

Re: Xquery to find/replace

Post by alex_jitianu » Mon Aug 10, 2015 3:56 pm

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 » Fri Aug 14, 2015 5:15 pm

Can you load a project using the doc function?

alex_jitianu
Posts: 682
Joined: Wed Nov 16, 2005 11:11 am

Re: Xquery to find/replace

Post by alex_jitianu » Mon Aug 17, 2015 8:52 am

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 » Fri Aug 21, 2015 5:26 pm

Is there a way to use my current project to generate a collection file? An export that I'm not seeing?

adrian
Posts: 2532
Joined: Tue May 17, 2005 4:01 pm

Re: Xquery to find/replace

Post by adrian » Fri Aug 21, 2015 7:17 pm

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