Guest User

Untitled

a guest
Oct 17th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. xquery version "1.0";
  2.  
  3. declare function local:encrypt($node){
  4. 'an encrypted value'
  5. };
  6.  
  7. declare function local:decrypt($node){
  8. 'a decrypted value'
  9. };
  10.  
  11.  
  12. declare function local:traverse-and-encrypt($nodes as node()*) as node()*{
  13. for $n in $nodes
  14. return if($n/@encrypted = 'true')
  15. then element{fn:node-name($n)}{
  16. for $a in $n/@*
  17. return if(fn:local-name($a) = 'encrypted')
  18. then attribute {'encrypted'} {'false'}
  19. else $a,
  20. local:decrypt($n/text())
  21. }
  22. else if($n/@encrypted = 'false')
  23. then element{fn:node-name($n)}{
  24. for $a in $n/@*
  25. return if(fn:local-name($a) = 'encrypted')
  26. then attribute {'encrypted'} {'true'}
  27. else $a,
  28. local:encrypt($n/text())
  29. }
  30. else element{fn:node-name($n)}{
  31. $n/@*,
  32. $n/text(),
  33. for $child in $n/*
  34. return local:traverse-and-encrypt($child)
  35. }
  36. };
  37.  
  38. let $doc :=
  39. <books>
  40. <book>
  41. <title encrypted="true">0234534rdf;skdlfsd</title>
  42. <author>J K. Rowling</author>
  43. <year>2005</year>
  44. <price>29.99</price>
  45. </book>
  46. <book>
  47. <title encrypted="false">Another book</title>
  48. <author test='testing attributes'>J K. Rowling</author>
  49. <year>2005</year>
  50. <price>29.99</price>
  51. </book>
  52. </books>
  53.  
  54. return local:traverse-and-encrypt($doc)
  55.  
  56. <books>
  57. <book>
  58. <title encrypted="false">a decrypted value</title>
  59. <author>J K. Rowling</author>
  60. <year>2005</year>
  61. <price>29.99</price>
  62. </book>
  63. <book>
  64. <title encrypted="true">an encrypted value</title>
  65. <author test="testing attributes">J K. Rowling</author>
  66. <year>2005</year>
  67. <price>29.99</price>
  68. </book>
  69. </books>
Add Comment
Please, Sign In to add comment