Page 1 of 1

Xquery to find/replace

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

Re: Xquery to find/replace

Posted: Mon Aug 10, 2015 3:56 pm
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

Re: Xquery to find/replace

Posted: Fri Aug 14, 2015 5:15 pm
by luxlunae
Can you load a project using the doc function?

Re: Xquery to find/replace

Posted: Mon Aug 17, 2015 8:52 am
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

Re: Xquery to find/replace

Posted: Fri Aug 21, 2015 5:26 pm
by luxlunae
Is there a way to use my current project to generate a collection file? An export that I'm not seeing?

Re: Xquery to find/replace

Posted: Fri Aug 21, 2015 7:17 pm
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