Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- xquery version "1.0" encoding "ISO-8859-1";
- declare namespace axit = "java:pl.axit.edi.processor.executors.xquery.XQueryExpressions";
- (:__________________________________________________________________________
- | |
- | AXIT GmbH |
- | |
- | [ProjectName] myMapping.xq |
- | |
- |___________________________________________________________________________|
- | |
- | Date | Coder | Version/Changes/Bug/Ticket |
- |___________________________________________________________________________|
- | |
- | dd.mm.YYYY | Surname Name | Initial Version 0.1 |
- |__________________________________________________________________________:)
- (: declared namespace :)
- declare namespace xf = "http://tempuri.org/myProjects/myMapping/";
- (: Mapping
- Output - fill your content in the brackets "{}" :)
- declare function xf:executeMapping($input){
- let $myFile := doc('file:///C:\Users\andras.balazs\Documents\projects\axit\scenario2\codefile.xml')
- return
- <Countries>
- {
- for $it in $input/Country
- return
- <Country>
- <Name>
- {
- xf:switchCountryToCode($myFile, $it)
- }
- </Name>
- <Language>
- {
- let $lang := data($it/Language)
- return $lang
- }
- </Language>
- </Country>
- }
- </Countries>
- };
- declare function xf:switchCountryToCode($myFile, $it){
- let $subString := xf:nameComparator($myFile,$it)
- (:let $ss := string-join($subString):)(: --sequence to string-- :)
- let $wrongAnswer := "XXX"
- let $isEmpty := empty($subString)
- return if ($isEmpty)
- then $wrongAnswer
- else $subString
- };
- declare function xf:nameComparator($myFile, $it){
- let $name := data($it/Name)
- let $wrongName := "XXX"
- let $correctName := ""
- for $x in $myFile/Countries/Country
- return if (data($x/Name)=$name)
- then data($x/Code)
- else ()
- };
- (: ********** Local environment, do not touch ***** :)
- declare variable $doc as xs:string external;
- declare variable $input := xf:doc($doc)/*;
- declare function xf:doc($val){doc($val)};
- declare function xf:doc-available($val){doc-available($val)};
- (: ********** Local environment, do not touch ***** :)
- (:
- (: ********** Final environment ********** :)
- declare variable $input as element() external;
- declare variable $EDI_Filename external;
- declare function xf:doc($val){axit:doc($val)};
- declare function xf:doc-available($val){axit:doc-available($val)};
- (: ********** Final environment ********** :)
- :)
- (: Output of the Mapping :)
- xf:executeMapping($input)
- (: ------------------SOME HINTS------------------------- :)
- (:
- 1. Example: Declaration of Variables
- let $string := "test"
- let $integer := 3
- let $boolean := true()
- return
- --------------------------------------------------------
- 2. Example: Loop
- for $a in $input/a
- return
- --------------------------------------------------------
- 3. Example: If Then Else
- if (2 > 0)
- then ("Two is bigger than zero This is correct.")
- else ("This is strange.")
- --------------------------------------------------------
- 4. Example: functions
- declare function myFunction(){
- "This is the output of my function."
- }
- OR
- declare function myFunction($parameter){
- "This is the parameter I use for this function: ", $parameter
- }
- --------------------------------------------------------
- 5. Example: Some useful XQuery functions
- fn: ... <- initiates an XQuery function, can also be left out
- - fn:data()
- - fn:tokenize()
- - fn:substring()
- - fn:string-length()
- - fn:concat()
- - fn:sum()
- :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement