L
L
lo0p3r2020-05-15 19:38:37
XSL & XSLT
lo0p3r, 2020-05-15 19:38:37

How to split a list using XSLT?

There is an XML with a complex structure, one of the elements of which is a list, the size of which is not known in advance.
Is it possible to split this list into several parts while keeping the rest of the structure intact? Well, almost untouched.
Example:

<L4>
  <AAA>a</AAA>
  <BBB>b</BBB>
  <CCC>
    <DDD>a:b:C:123.400.01</DDD>
    <DDD>a:b:C:123.400.02</DDD>
    <DDD>a:b:C:123.400.03</DDD>
    <DDD>a:b:D:123.401.01</DDD>
    <DDD>a:b:D:123.401.02</DDD>
    <DDD>a:b:E:123.402.01</DDD>
  </CCC>
  <DDD>d</DDD>
  ...
  <ZZZ>z</ZZZ>
</L4>

Differences - different beginning of the values ​​of the list elements - a:b:C, a:b:D and a:b:E
As a result, we get such a list of elements
<L4>
  <AAA>a</AAA>
  <BBB>b</BBB>
  <CCC>
    <DDD>a:b:C:123.400.01</DDD>
    <DDD>a:b:C:123.400.02</DDD>
    <DDD>a:b:C:123.400.03</DDD>
  </CCC>
  <DDD>d</DDD>
  ...
  <ZZZ>z</ZZZ>
</L4>
<L4>
  <AAA>a</AAA>
  <BBB>b</BBB>
  <CCC>
    <DDD>a:b:D:123.401.01</DDD>
    <DDD>a:b:D:123.401.02</DDD>
  </CCC>
  <DDD>d</DDD>
  ...
  <ZZZ>z</ZZZ>
</L4>
<L4>
  <AAA>a</AAA>
  <BBB>b</BBB>
  <CCC>
    <DDD>a:b:E:123.402.01</DDD>
  </CCC>
  <DDD>d</DDD>
  ...
  <ZZZ>z</ZZZ>
</L4>

Those. the element will be repeated according to the number of different a:b:X: elements (there can be 1-3 of them).

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question