Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- xquery version "1.0";
- declare function local:encrypt($node){
- 'an encrypted value'
- };
- declare function local:decrypt($node){
- 'a decrypted value'
- };
- declare function local:traverse-and-encrypt($nodes as node()*) as node()*{
- for $n in $nodes
- return if($n/@encrypted = 'true')
- then element{fn:node-name($n)}{
- for $a in $n/@*
- return if(fn:local-name($a) = 'encrypted')
- then attribute {'encrypted'} {'false'}
- else $a,
- local:decrypt($n/text())
- }
- else if($n/@encrypted = 'false')
- then element{fn:node-name($n)}{
- for $a in $n/@*
- return if(fn:local-name($a) = 'encrypted')
- then attribute {'encrypted'} {'true'}
- else $a,
- local:encrypt($n/text())
- }
- else element{fn:node-name($n)}{
- $n/@*,
- $n/text(),
- for $child in $n/*
- return local:traverse-and-encrypt($child)
- }
- };
- let $doc :=
- <books>
- <book>
- <title encrypted="true">0234534rdf;skdlfsd</title>
- <author>J K. Rowling</author>
- <year>2005</year>
- <price>29.99</price>
- </book>
- <book>
- <title encrypted="false">Another book</title>
- <author test='testing attributes'>J K. Rowling</author>
- <year>2005</year>
- <price>29.99</price>
- </book>
- </books>
- return local:traverse-and-encrypt($doc)
- <books>
- <book>
- <title encrypted="false">a decrypted value</title>
- <author>J K. Rowling</author>
- <year>2005</year>
- <price>29.99</price>
- </book>
- <book>
- <title encrypted="true">an encrypted value</title>
- <author test="testing attributes">J K. Rowling</author>
- <year>2005</year>
- <price>29.99</price>
- </book>
- </books>
Add Comment
Please, Sign In to add comment