Version 7.1 by Erik Bakker on 2022/07/26 09:05

Hide last authors
Erik Bakker 2.1 1 {{container}}{{container layoutStyle="columns"}}(((
Erik Bakker 6.1 2 Within the crash course, we already explained XPath conceptually. In that same microlearning, we looked at some more uncomplicated cases of using XPath within your transformation. If you need to brush up on that knowledge, please check out this [[microlearning>>doc:Main.eMagiz Academy.Microlearnings.Crash Course.Crash Course Platform.crashcourse-platform-create-transformation-xpath-basic.WebHome||target="blank"]]. In the intermediate microlearning on this subject, we built upon that knowledge. Please check out this [[microlearning>>doc:Main.eMagiz Academy.Microlearnings.Intermediate Level.Create your transformations.intermediate-create-your-transformations-xpath-intermediate.WebHome||target="blank"]] if you need a refresher on that. In the [[microlearning>>doc:Main.eMagiz Academy.Microlearnings.Advanced Level.Create your transformations.advanced-create-your-transformations-xpath-advanced.WebHome||target="blank"]] that followed, we built upon that knowledge and looked at some concrete, practical examples that could be useful in your project. In this microlearning, we will wrap the concept of XPath by looking at three complex XPath alternatives that are sometimes needed when dealing with messages in eMagiz.
eMagiz 1.1 3
Erik Bakker 2.1 4 Should you have any questions, please get in touch with [[academy@emagiz.com>>mailto:academy@emagiz.com]].
eMagiz 1.1 5
6 == 1. Prerequisites ==
7
Erik Bakker 6.1 8 * Expert knowledge of the eMagiz platform
Erik Bakker 4.1 9 * [[XPath Basic>>doc:Main.eMagiz Academy.Microlearnings.Crash Course.Crash Course Platform.crashcourse-platform-create-transformation-xpath-basic.WebHome||target="blank"]]
Erik Bakker 5.1 10 * [[XPath Intermediate>>doc:Main.eMagiz Academy.Microlearnings.Intermediate Level.Create your transformations.intermediate-create-your-transformations-xpath-intermediate.WebHome||target="blank"]]
Erik Bakker 6.1 11 * [[XPath Advanced>>doc:Main.eMagiz Academy.Microlearnings.Advanced Level.Create your transformations.advanced-create-your-transformations-xpath-advanced.WebHome||target="blank"]]
eMagiz 1.1 12
13
14 == 2. Key concepts ==
15
Erik Bakker 7.1 16 This microlearning focuses on very complex XPath operations.
eMagiz 1.1 17
Erik Bakker 7.1 18 With XPath Expert, we mean learning that XPath options are sometimes very complex but could benefit you in specific cases in your daily work.
eMagiz 1.1 19
Erik Bakker 7.1 20 Some of the very complex XPath options are:
eMagiz 1.1 21
Erik Bakker 7.1 22 * matches
23 * replace
24 * tokenize
eMagiz 1.1 25
Erik Bakker 7.1 26 == 3. XPath Expert ==
eMagiz 1.1 27
Erik Bakker 7.1 28 Within the crash course, we already explained XPath conceptually. In that same microlearning, we looked at some more uncomplicated cases of using XPath within your transformation. If you need to brush up on that knowledge, please check out this [[microlearning>>doc:Main.eMagiz Academy.Microlearnings.Crash Course.Crash Course Platform.crashcourse-platform-create-transformation-xpath-basic.WebHome||target="blank"]]. In the intermediate microlearning on this subject, we built upon that knowledge. Please check out this [[microlearning>>doc:Main.eMagiz Academy.Microlearnings.Intermediate Level.Create your transformations.intermediate-create-your-transformations-xpath-intermediate.WebHome||target="blank"]] if you need a refresher on that. In the [[microlearning>>doc:Main.eMagiz Academy.Microlearnings.Advanced Level.Create your transformations.advanced-create-your-transformations-xpath-advanced.WebHome||target="blank"]] that followed, we built upon that knowledge and looked at some concrete, practical examples that could be useful in your project. In this microlearning, we will wrap the concept of XPath by looking at three complex XPath alternatives that are sometimes needed when dealing with messages in eMagiz.
eMagiz 1.1 29
Erik Bakker 7.1 30 Some of the very complex XPath options are:
eMagiz 1.1 31
Erik Bakker 7.1 32 * matches
33 * replace
34 * tokenize
eMagiz 1.1 35
Erik Bakker 7.1 36 === 3.1 matches ===
eMagiz 1.1 37
Erik Bakker 7.1 38 Sometimes, you want to determine whether a specific value within your payload matches a pattern. In those cases, you can use the XPath function called matches. The function will return true if the supplied string matches a given regular expression. So, for example, if you want to check whether your OrderID contains exactly seven digits and nothing else, the following XPath expression will work for your use case.
eMagiz 1.1 39
Erik Bakker 7.1 40 matches(OrderID,'^\d{7}$')
eMagiz 1.1 41
Erik Bakker 7.1 42 As a result, you will get a true or false back which you can then use as a filter or within an if-then-else construction.
eMagiz 1.1 43
Erik Bakker 7.1 44 === 3.2 replace ===
eMagiz 1.1 45
Erik Bakker 7.1 46 The replace function has many similarities with the matches function. It builds on the premise of the matches function, but instead of returning a true or false, you can state with what you want to replace the matched string. In other words, this function returns a string produced from the input string by replacing any substrings that match a given regular expression with a supplied replacement string.
eMagiz 1.1 47
Erik Bakker 7.1 48 When we apply this to our earlier example, we can state that when the OrderID contains any non-digit, we will replace this value with nothing. This will lead to the following XPath expression.
eMagiz 1.1 49
Erik Bakker 7.1 50 replace(OrderID,'\D','')
eMagiz 1.1 51
Erik Bakker 7.1 52 With a given input string of 12C34A567, the returned result will be 1234567.
eMagiz 1.1 53
Erik Bakker 7.1 54 === 3.3 tokenize ===
eMagiz 1.1 55
Erik Bakker 7.1 56 The tokenize function can split a string into multiple entries for you. This is particularly useful when you want to match an input string to a list of possible values that are valid for that string. For example, the function returns a sequence of strings constructed by splitting the input wherever a separator is found; the separator is any substring that matches a given regular expression.
eMagiz 1.1 57
Erik Bakker 7.1 58 So, for example, when the input string for AddressID is "street,housenumber,housenumberaddition" and you want to tokenize this with the help of the separator, you could use, in this example, the comma between the values as the separator. This will lead to the following XPath expression.
eMagiz 1.1 59
Erik Bakker 7.1 60 tokenize(AddressID,',')
eMagiz 1.1 61
Erik Bakker 7.1 62 The given input detailed above will result in the following output: street housenumber housenumberaddition.
eMagiz 1.1 63
64 == 4. Assignment ==
65
66 Check out which of the XPaths we have discussed today can be found within your project.
67 This assignment can be completed within the (Academy) project you created/used in the previous assignment.
68
69 == 5. Key takeaways ==
70
Erik Bakker 7.1 71 Some of the very complex XPath options are:
eMagiz 1.1 72
Erik Bakker 7.1 73 * matches
74 * replace
75 * tokenize
eMagiz 1.1 76
77 == 6. Suggested Additional Readings ==
78
Erik Bakker 7.1 79 If you are interested in this topic and want more information on it, please read the help text provided by eMagiz and read more information on the following links:
eMagiz 1.1 80
Erik Bakker 7.1 81 * http://www.xsltfunctions.com/xsl/fn_matches.html
82 * http://www.xsltfunctions.com/xsl/fn_replace.html
83 * http://www.xsltfunctions.com/xsl/fn_tokenize.html
eMagiz 1.1 84
85 == 7. Silent demonstration video ==
86
Erik Bakker 2.1 87 As this is more of theoretical microlearning, there is no video accompanying the microlearning.)))((({{toc/}}))){{/container}}{{/container}}