Hi I have the following XML code:
<?xml version="1.0" encoding="utf-8"?>
<UserStaging>
<NeuroRKStaging>
<Stage Type="REM" Start="0" />
<Stage Type="Stage3" Start="150" />
<Stage Type="Movement" Start="3030" />
<Stage Type="Wake" Start="3150" />
<Stage Type="Stage2" Start="4680" />
<Stage Type="Stage3" Start="5340" />
<Stage Type="Movement" Start="6090" />
<Stage Type="Wake" Start="6480" />
<Stage Type="Stage1" Start="9330" />
<Stage Type="Stage3" Start="10290" />
</NeuroRKStaging>
</UserStaging>
And I have to get it in this format:
<?xml version="1.0" encoding="utf-8"?>
<stages>
<epoch><epoch_start>0</epoch_start><epoch_end>150</epoch_end><stage>REM</stage></epoch>
<epoch><epoch_start>150</epoch_start><epoch_end>3150</epoch_end><stage>NREM3</stage></epoch>
<epoch><epoch_start>3150</epoch_start><epoch_end>4680</epoch_end><stage>Wake</stage></epoch>
<epoch><epoch_start>4680</epoch_start><epoch_end>5340</epoch_end><stage>NREM2</stage></epoch>
<epoch><epoch_start>5340</epoch_start><epoch_end>6480</epoch_end><stage>NREM3</stage></epoch>
<epoch><epoch_start>6480</epoch_start><epoch_end>9330</epoch_end><stage>Wake</stage></epoch>
<epoch><epoch_start>9330</epoch_start><epoch_end>10290</epoch_end><stage>NREM1</stage></epoch>
<epoch><epoch_start>10290</epoch_start><epoch_end>99999</epoch_end><stage>NREM3</stage></epoch>
</stages>
There are 5 types/stages
Stage1 transforms to NREM1
Stage2 transforms to NREM2
Stage3 transforms to NREM3
REM remains REM
Wake remains Wake
All lines with Type="Movement" should be deleted and only after that the data should be transformed. The "Start" of every following Stage is going to be the "epoch_end" of the one before. For the last epoch the epoch_end should be 99999
How would a xsl stylesheet look like to do that?
With XSLT 3's
xsl:iterate
you can pass on the previously processed item and then output it with the right start and end values, also taking care of the last item withxsl:on-completion
:https://xsltfiddle.liberty-development.net/bFN1y8Z/1