Last modified by Eva Torken on 2023/08/10 12:06

Show last authors
1 {{container}}
2 {{container layoutStyle="columns"}}
3 (((
4 Within the crash course, we already explained XPath conceptually. In that same microlearning, we also 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||target="blank"]]. In this microlearning, we will build upon that knowledge and look at some concrete, practical examples that we see are used a lot across projects.
5
6 Should you have any questions, please get in touch with academy@emagiz.com.
7
8 == 1. Prerequisites ==
9
10 * Basic knowledge of the eMagiz platform
11
12 == 2. Key concepts ==
13
14 This microlearning focuses on XPath Intermediate in the context of transformations.
15
16 With XPath Intermediate, we mean Learning which XPath options are widely used and could benefit you in your daily work.
17
18 Some of the more widely used XPath options are:
19
20 * if then else
21 * concat
22 * exists check
23 * empty check
24 * normalize-space
25 * substring
26
27 == 3. Transformation - XPath Intermediate ==
28
29 Within the crash course, we already explained XPath conceptually. In that same microlearning, we also looked at some more straightforward 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||target="blank"]]. In this microlearning, we will build upon that knowledge and look at some concrete, practical examples that we see are used a lot across projects.
30
31 Some of the more widely used XPath options are:
32
33 * if then else
34 * concat
35 * exists check
36 * empty check
37 * normalize-space
38 * substring
39
40 === 3.1 If then else ===
41
42 One of the most used XPath constructions is the if then else construction. With the help of this construction, you define a condition (the if), you define what happens if the condition returns true (the then), and you define what happens when the condition returns false (the else). When written in XPath this results in the following notation: **if(SomeAttribute='One') then SomeOtherAttribute else 'two'**.
43
44 Note that you can verify what your input is in each of the three parts of the XPath. So I could also have replaced SomeOtherAttribute with a static value, for example. Or I could have used a parameter. Or any of the other options available.
45
46 === 3.2 Concat ===
47
48 The concat option is a variation on the string-join we saw in the XPath Basic [[microlearning>>doc:Main.eMagiz Academy.Microlearnings.Crash Course.Crash Course Platform.crashcourse-platform-create-transformation-xpath-basic||target="blank"]]. The significant difference between the concat and the string-join is that with the concat, you do not define one single separator between the various elements. With the concat, you define per step how certain parts should be linked together. So, for example, **concat(SomeAttribute,' ', SomeOtherAttribute,'-', AThirdAttribute, AFourthAttribute)** uses different separators between the various elements we want to join together in a new string.
49
50 === 3.3 Exists check ===
51
52 When you have a standard filter in the transformation tooling of eMagiz, it will perform a check to determine whether the input attribute exists within the input message. You can use the same logic when writing a custom XPath (as part of a custom snippet, for example). The notation is straightforward. The exists check is written as **exists(SomeAttribute)**. Note that when you only do an exists check, and the input attribute is a string, this check is no guarantee that the attribute is filled with a relevant value. This means that when your following definition expects a **nonEmptyString**, only doing a exists check is not sufficient.
53
54 === 3.4 Empty check ===
55
56 For those scenarios, we have what we call the empty check. With the empty check (which is frequently used in combination with the exists check), you also check whether the attribute is filled with something. The empty check is written as **SomeAttribute !=''**. Combined with the empty check, it is an important defense against validation errors on nonEmptyString attributes.
57
58 === 3.5 Normalize-space ===
59
60 The normalize-space function strips leading and trailing white-space from a string replaces sequences of white-space characters by a single space and return the resulting string. So, in essence, if my input attribute called SomeAttribute contains the value -> 'This is a test '. The result of the normalize-space action would then be -> 'This is a test'. Note that the '.' in both examples is placed there to illustrate the input and output string. The notation of the normalize-space function is **normalize-space(SomeAttribute)**.
61
62 === 3.6 Substring ===
63
64 Sometimes you need to get part of a string in your output. The default transformation tooling of eMagiz provides you with a friendly UI for this option in which you only have to define the start position and the length of the string you want as your output.
65
66 [[image:Main.Images.Microlearning.WebHome@intermediate-create-your-transformations-xpath-intermediate--substring-transformation-tooling.png]]
67
68 Translating that into an XPath would yield the following result: **substring(SomeAttribute,1,9)**.
69
70 With this, we have learned about some frequently used XPaths in (custom) transformations that we see are being used within the eMagiz platform. We will pick up the subject of XPath later on once more to delve even deeper into the world of XPath.
71
72 == 4. Key takeaways ==
73
74 Some of the more widely used XPath options are:
75
76 * if then else
77 * concat
78 * exists check
79 * empty check
80 * normalize-space
81 * substring
82
83 == 5. Suggested Additional Readings ==
84
85 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 link:
86
87 * [[Xpath Intro>>https://www.w3schools.com/xml/xpath_intro.asp||target="blank"]]
88 )))
89 ((({{toc/}}))){{/container}}
90 {{/container}}