Can I add an element based on previous data? I would like to add that to an existing complex XSLT ruleset. That's why I wouldn't like to start with another program.
A simplified version of the problem:
<featurecollection>
<feature>
<id>1235</id> <!-- same id -->
<time>100</time> <!-- older ---->
</feature>
<feature>
<id>1235</id> <!-- same id -->
<time>101</time> <!-- newer ---->
</feature>
<feature>
<id>1236</id> <!-- unique id ->
<time>102</time> <!-- is new ---->
</feature>
</featurecollection>
I would like to add an extra element based upon the time of an existing id.
<featurecollection>
<feature>
<id>1235</id> <!-- same id -->
<time>100</time> <!-- older ---->
<sequence>first</time>
</feature>
<feature>
<id>1235</id> <!-- same id -->
<time>101</time> <!-- newer ---->
<sequence>second</time>
</feature>
<feature>
<id>1236</id> <!-- unique id ->
<time>102</time> <!-- is new ---->
<sequence>second</time>
</feature>
</featurecollection>
Any id will be used either once or twice. With similar id's the oldest is always before the newest. The id field is always before the <time>
field.
How can I add that <sequence>
element? I could use a Java extension, but then I am operating within another element. Via the Saxon lib I can work with XSLT 2.0.
ADDED: A more elaborate version of the problem is the following XML:
<featurecollection>
<feature>
<object>
<identification>
<id>1</id>
</identification>
<time>20230804120304</time>
<!-- insert here: <sequence>first</sequence> -->
</object>
<object>
<identification>
<id>1</id>
</identification>
<time>20230804120305</time>
<!-- insert here: <sequence>second</sequence> -->
</object>
</feature>
<feature>
<object>
<identification>
<id>2</id>
</identification>
<time>20230804120304</time>
<!-- insert here: <sequence>second</sequence> -->
</object>
</feature>
</featurecollection>
UPDATE: looking back, thank you all very much for the great answers!