I have block of data sample in XML. Each data has a attribute called “switch” specifying if a switch is off or on ( default value is off ).
The goal is to add this information thanks to XSLT as an attribute of the block. This new atttribute “action” specifies whether the switch was turned off or on within the data block.
Case 1:
<block>
<data switch="true">2.4</data>
<data switch="true">2.4</data>
<data>270.0</data>
<data>244.79999999999998</data>
<data>330.59999999999997</data>
</block>
transformed in
<block action="turnedOFF">
<data switch="true">2.4</data>
<data switch="true">2.4</data>
<data>270.0</data>
<data>244.79999999999998</data>
<data>330.59999999999997</data>
</block>
Case 2: Reversely, the xml below:
<block>
<data>270.0</data>
<data>244.79999999999998</data>
<data>330.59999999999997</data>
<data switch="true">2.4</data>
<data switch="true">2.4</data>
</block>
is to be transformed into:
<block action="turnedON">
<data>270.0</data>
<data>244.79999999999998</data>
<data>330.59999999999997</data>
<data switch="true">2.4</data>
<data switch="true">2.4</data>
</block>
If you know there can be at most one transition of the
switchattribute in the<data>elements, it should be enough to check the values of the first and last<data>element in a<block>. Here’s an untested attempt:Update
I fixed a few errors and verified the transform. This works.