Hi to all,
Maybe someone could help me. I want to transform the structure of a xml file.
I have this input.xml:
<?xml version="1.0" encoding="utf-8"?>
<votings>
<file name="Reference 19762">
<case id="No. 3 Div. 870">
<j v="1">Peter</j>
<j v="1">Ely</j>
<j v="9">Mark</j>
</case>
<case id="No. 3 Div. 887">
<j v="1">Mary</j>
<j v="9">Peter</j>
<j v="1">Ely</j>
<j v="1">Perry</j>
<j v="1">Mark</j>
</case>
</file>
</votings>
and the required output should be:
<Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="6" x:FullColumns="1"
x:FullRows="1" ss:DefaultColumnWidth="60" ss:DefaultRowHeight="15">
<Column ss:Width="30.75"/>
<Column ss:Width="67.5" ss:Span="1"/>
<Row ss:AutoFitHeight="0">
<Cell ss:Index="2"><Data ss:Type="String">No. 3 Div. 870</Data></Cell>
<Cell><Data ss:Type="String">No. 3 Div. 887</Data></Cell>
</Row>
<Row ss:AutoFitHeight="0">
<Cell><Data ss:Type="String">Ely</Data></Cell>
<Cell><Data ss:Type="Number">1</Data></Cell>
<Cell><Data ss:Type="Number">1</Data></Cell>
</Row>
<Row ss:AutoFitHeight="0">
<Cell><Data ss:Type="String">Mark</Data></Cell>
<Cell><Data ss:Type="Number">9</Data></Cell>
<Cell><Data ss:Type="Number">1</Data></Cell>
</Row>
<Row ss:AutoFitHeight="0">
<Cell><Data ss:Type="String">Mary</Data></Cell>
<Cell><Data ss:Type="Number">0</Data></Cell>
<Cell><Data ss:Type="Number">1</Data></Cell>
</Row>
<Row ss:AutoFitHeight="0">
<Cell><Data ss:Type="String">Perry</Data></Cell>
<Cell><Data ss:Type="Number">0</Data></Cell>
<Cell><Data ss:Type="Number">1</Data></Cell>
</Row>
<Row ss:AutoFitHeight="0">
<Cell><Data ss:Type="String">Peter</Data></Cell>
<Cell><Data ss:Type="Number">1</Data></Cell>
<Cell><Data ss:Type="Number">9</Data></Cell>
</Row>
</Table>
As you can see, in input.xml there are 2 blocks of "cases" with names (it could be more than 2 "cases" blocks. e.g 5, 7, 8 etc.).
In both "cases" blocks appear some names repeated (Peter, Ely and Mark appear in both blocks)
Then, in the output the "Row" blocks should be obtained as follow:
Block 1:
<Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="6" x:FullColumns="1"
Variables here are in red:
ExpandedColumnCount = Number of "Cases" blocks + 1 = 2 +1 = 3
ExpandedRowCount = Number of unique names + 1 = 5 + 1 = 6
Block 2 (the first "Row" block):
<Row ss:AutoFitHeight="0">
<Cell ss:Index="2"><Data ss:Type="String">No. 3 Div. 870</Data></Cell>
<Cell><Data ss:Type="String">No. 3 Div. 887</Data></Cell>
</Row>
The values in red should be taken from "case id" in "cases" blocks.
Blocks 3,4,5...N ("Row" blocks for each unique name):
<Row ss:AutoFitHeight="0">
<Cell><Data ss:Type="String">Ely</Data></Cell>
<Cell><Data ss:Type="Number">1</Data></Cell>
<Cell><Data ss:Type="Number">1</Data></Cell>
</Row>
The values in red are taken from "cases" blocks, but needs to look up unique names and show a unique "Row" block for each name and
all related values for each name within the same "Row" block as shown above.
I really hope you could help me with this. I'm a kind of beginner in this type of scripts.
Thanks in advance.
Regards.