XSLT: Splitting none continues Elements/Grouping continues Elements

Posted by Gerald on Stack Overflow See other posts from Stack Overflow or by Gerald
Published on 2010-03-08T06:32:41Z Indexed on 2010/03/08 6:36 UTC
Read the original article Hit count: 458

Filed under:
|

Hi! Need some help with this problem in implementing with Xslt, I had already implemented a java code of this one using sax parser but it is a troublesome due to customer request to change something... so we are doing it now using an XSLT with don't need to be compiled and deployed to a web server.

I have an xml like the one below
Example 1:
<ShotRows>
<ShotRow row="3" col="3" bit="1" position="1"/>
<ShotRow row="3" col="4" bit="1" position="2"/>
<ShotRow row="3" col="5" bit="1" position="3"/>
<ShotRow row="3" col="6" bit="1" position="4"/>
<ShotRow row="3" col="7" bit="1" position="5"/>
<ShotRow row="3" col="8" bit="1" position="6"/>
<ShotRow row="3" col="9" bit="1" position="7"/>
<ShotRow row="3" col="10" bit="1" position="8"/>
<ShotRow row="3" col="11" bit="1" position="9"/>
</ShotRows>

Output 1:
<ShotRows>
<ShotRow row="3" colStart="3" colEnd="11" />
</ShotRows>
--> Be cause the col is continues from 3 to 11

Example 2:
<ShotRows>
<ShotRow row="3" col="3" bit="1" position="1"/>
<ShotRow row="3" col="4" bit="1" position="2"/>
<ShotRow row="3" col="6" bit="1" position="3"/>
<ShotRow row="3" col="7" bit="1" position="4"/>
<ShotRow row="3" col="8" bit="1" position="5"/>
<ShotRow row="3" col="10" bit="1" position="6"/>
<ShotRow row="3" col="11" bit="1" position="7"/>
<ShotRow row="3" col="15" bit="1" position="8"/>
<ShotRow row="3" col="19" bit="1" position="9"/>
</ShotRows>

Output 2:
<ShotRows>
<ShotRow row="3" colStart="3" colEnd="4" />
<ShotRow row="3" colStart="6" colEnd="8" />
<ShotRow row="3" colStart="10" colEnd="11" />
<ShotRow row="3" colStart="15" colEnd="15" />
<ShotRow row="3" colStart="19" colEnd="19" />
</ShotRows>
--> Basic idea is to group any continues col into one element, like the col 3 to 4, col 6 to 8, col 10 to 11, col 15 is only one, and col 19 is only one.

Thanks in advance.

Sincerely, Gerald

© Stack Overflow or respective owner

Related posts about xslt

Related posts about Xml