Last active
March 7, 2019 09:58
-
-
Save tuurma/1dbe54a2cab665be3a154a9aeef5d96f to your computer and use it in GitHub Desktop.
XQuery update examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(: insert attribute :) | |
for $i in collection('/db/apps/my-data')//nym[not(@cert)] | |
return | |
update insert attribute cert {'high'} into $i | |
(: insert more than one node :) | |
update insert (<a/>, <b/>) into //foo | |
(: make sure to explicitly specify namespaces when inserting/replacing nodes :) | |
update insert <surname xmlns="http://www.tei-c.org/ns/1.0">Huo</surname> into //tei:name[.='Otmar'] | |
(: replace text content of an element :) | |
declare namespace tei="http://www.tei-c.org/ns/1.0"; | |
for $i in collection("/db/apps/my-data")//tei:m[@n="3"][.="τ"] | |
return update replace $i/text() with '(V)τ' | |
(: but better do the same with update VALUE :) | |
for $i in collection("/db/apps/my-data")//tei:m[@n="3"][.="τ"] | |
return update value $i with '(V)τ' | |
(: not only text content can be updated with update value :) | |
for $i in //name[. = "Otmar"] | |
return update value $i with <forename>Oti</forename> | |
(: RENAME node :) | |
for $email in //email | |
update rename $email as 'mail' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment