-
I have following input file:
and want to insert an additional item between "item2" and "item3":
How can I do this? I have tried following transform.jslt file:
but it replaces "item2" by "item2.1" which is understandable because of the "else" statement. What I want to do is either to output "item2" inside the if block (additionally to "item2.1") or an "endif" instead of "else" so that "item2" is printed when the if clause is true (then the if clause has to be changed to if(.name == "item1")). Any suggestions how to handle this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
This snipped will solve the exact example you're describing, although I guess it may not be general enough for your real use case. But it might be enough to show you how to solve it.
|
Beta Was this translation helpful? Give feedback.
-
The trick is to search for the index of that item, then use that in the expression above to cut the array at the right point. This should work:
|
Beta Was this translation helpful? Give feedback.
-
Thank you for the tip. I have solved it. JSLT code:
|
Beta Was this translation helpful? Give feedback.
The trick is to search for the index of that item, then use that in the expression above to cut the array at the right point.
This should work: