Guest User

Untitled

a guest
May 22nd, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. import-and-process.xq
  2. import module namespace acs = 'http://whatever.net' at 'lib.xqm';
  3. declare variable $filename external;
  4.  
  5. acs:import-and-process($filename)
  6.  
  7. import-all.xq
  8. import module namespace acs = 'http://whatever.net' at 'lib.xqm';
  9. declare variable $dir external;
  10.  
  11. (:
  12. : for-each(file:list($dir, xs:boolean("false"), "*.xml"), acs:import-and-process(?))
  13. :)
  14.  
  15. for $file in file:list($dir, xs:boolean("false"), "*.xml")
  16. return acs:import-and-process(file:current-dir() || $dir || '\' || $file)
  17.  
  18. lib.xqm
  19. module namespace acs = 'http://whatever.net';
  20.  
  21. declare function acs:hello($world) {
  22. 'Hello' || $world
  23. };
  24.  
  25. declare updating function acs:import-and-process($filename) {
  26. (: find timestamp in filename :)
  27. (: get package and file into variables :)
  28. let $mydoc := doc($filename)
  29. let $datetime := file:last-modified($filename)
  30. let $package := substring-before($mydoc/testrun/testsuite/@name/data(), ".")
  31. let $file := substring-after($mydoc/testrun/testsuite/@name/data(), ".")
  32. let $testrun := file:name($filename)
  33.  
  34. (: add file to database :)
  35. (: insert package, file, and timestamp attributes to every testcase :)
  36. return
  37. copy $mycopy := $mydoc
  38. modify (for $testcase in $mycopy//testcase
  39. return insert nodes
  40. (attribute package {$package},
  41. attribute file {$file},
  42. attribute xs:datetime {$datetime},
  43. attribute testrun {$testrun})
  44. into $testcase)
  45. return
  46. (db:replace("TestResults", file:name($filename), $mycopy)),
  47. (db:flush("TestResults"))
  48. };
  49.  
  50. basex -i TestResults -b dir=TestResults import-all.xq
  51. : Updates are not written back.
Advertisement
Add Comment
Please, Sign In to add comment