Advertisement
weeez

2_3

Jun 9th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. xquery version "1.0" encoding "ISO-8859-1";
  2. declare namespace axit = "java:pl.axit.edi.processor.executors.xquery.XQueryExpressions";
  3.  
  4. (:__________________________________________________________________________
  5. | |
  6. | AXIT GmbH |
  7. | |
  8. | [ProjectName] myMapping.xq |
  9. | |
  10. |___________________________________________________________________________|
  11. | |
  12. | Date | Coder | Version/Changes/Bug/Ticket |
  13. |___________________________________________________________________________|
  14. | |
  15. | dd.mm.YYYY | Surname Name | Initial Version 0.1 |
  16. |__________________________________________________________________________:)
  17.  
  18. (: declared namespace :)
  19. declare namespace xf = "http://tempuri.org/myProjects/myMapping/";
  20.  
  21. (: Mapping
  22. Output - fill your content in the brackets "{}" :)
  23. declare function xf:executeMapping($input){
  24. let $myFile := doc('file:///C:\Users\andras.balazs\Documents\projects\axit\scenario2\codefile.xml')
  25.  
  26. return
  27. <Countries>
  28. {
  29. for $it in $input/Country
  30. return
  31. <Country>
  32. <Name>
  33. {
  34. xf:switchCountryToCode($myFile, $it)
  35. }
  36. </Name>
  37. <Language>
  38. {
  39. let $lang := data($it/Language)
  40. return $lang
  41. }
  42. </Language>
  43. </Country>
  44. }
  45. </Countries>
  46. };
  47.  
  48. declare function xf:switchCountryToCode($myFile, $it){
  49. let $subString := xf:nameComparator($myFile,$it)
  50. (:let $ss := string-join($subString):)(: --sequence to string-- :)
  51. let $wrongAnswer := "XXX"
  52.  
  53. let $isEmpty := empty($subString)
  54. return if ($isEmpty)
  55. then $wrongAnswer
  56. else $subString
  57. };
  58.  
  59. declare function xf:nameComparator($myFile, $it){
  60. let $name := data($it/Name)
  61. let $wrongName := "XXX"
  62. let $correctName := ""
  63.  
  64. for $x in $myFile/Countries/Country
  65. return if (data($x/Name)=$name)
  66. then data($x/Code)
  67. else ()
  68. };
  69.  
  70. (: ********** Local environment, do not touch ***** :)
  71. declare variable $doc as xs:string external;
  72. declare variable $input := xf:doc($doc)/*;
  73. declare function xf:doc($val){doc($val)};
  74. declare function xf:doc-available($val){doc-available($val)};
  75. (: ********** Local environment, do not touch ***** :)
  76.  
  77. (:
  78. (: ********** Final environment ********** :)
  79. declare variable $input as element() external;
  80. declare variable $EDI_Filename external;
  81. declare function xf:doc($val){axit:doc($val)};
  82. declare function xf:doc-available($val){axit:doc-available($val)};
  83. (: ********** Final environment ********** :)
  84. :)
  85.  
  86. (: Output of the Mapping :)
  87. xf:executeMapping($input)
  88.  
  89.  
  90. (: ------------------SOME HINTS------------------------- :)
  91. (:
  92. 1. Example: Declaration of Variables
  93.  
  94. let $string := "test"
  95. let $integer := 3
  96. let $boolean := true()
  97. return
  98.  
  99. --------------------------------------------------------
  100. 2. Example: Loop
  101.  
  102. for $a in $input/a
  103. return
  104.  
  105. --------------------------------------------------------
  106. 3. Example: If Then Else
  107.  
  108. if (2 > 0)
  109. then ("Two is bigger than zero This is correct.")
  110. else ("This is strange.")
  111.  
  112. --------------------------------------------------------
  113. 4. Example: functions
  114.  
  115. declare function myFunction(){
  116. "This is the output of my function."
  117. }
  118.  
  119. OR
  120.  
  121. declare function myFunction($parameter){
  122. "This is the parameter I use for this function: ", $parameter
  123. }
  124.  
  125. --------------------------------------------------------
  126. 5. Example: Some useful XQuery functions
  127.  
  128. fn: ... <- initiates an XQuery function, can also be left out
  129.  
  130. - fn:data()
  131. - fn:tokenize()
  132. - fn:substring()
  133. - fn:string-length()
  134. - fn:concat()
  135. - fn:sum()
  136.  
  137. :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement