I had an xls book saved as xml. There I have 1st rows with header and other rows with data. In xml it looks:
<Row ss:AutoFitHeight="0">
<Cell><Data ss:Type="String">Header 1 - id</Data><NamedCell
ss:Name="_FilterDatabase"/></Cell>
<Cell><Data ss:Type="String">Header 2 - Version</Data><NamedCell ss:Name="_FilterDatabase"/></Cell>
<Cell><Data ss:Type="String">Header 3 - some data...</Data><NamedCell
ss:Name="_FilterDatabase"/></Cell>
</Row>
<Row ss:AutoFitHeight="0">
<Cell><Data ss:Type="String">id001</Data><NamedCell
ss:Name="_FilterDatabase"/></Cell>
<Cell><Data ss:Type="Number">1</Data><NamedCell ss:Name="_FilterDatabase"/></Cell>
<Cell><Data ss:Type="String">blabla</Data><NamedCell
ss:Name="_FilterDatabase"/></Cell>
</Row>
<Row ss:AutoFitHeight="0">
<Cell><Data ss:Type="String">id001</Data><NamedCell
ss:Name="_FilterDatabase"/></Cell>
<Cell><Data ss:Type="Number">2</Data><NamedCell ss:Name="_FilterDatabase"/></Cell>
<Cell><Data ss:Type="String">blabla</Data><NamedCell
ss:Name="_FilterDatabase"/></Cell>
</Row>
<Row ss:AutoFitHeight="0">
<Cell><Data ss:Type="String">id002</Data><NamedCell
ss:Name="_FilterDatabase"/></Cell>
<Cell><Data ss:Type="Number">1</Data><NamedCell ss:Name="_FilterDatabase"/></Cell>
<Cell><Data ss:Type="String">blabla</Data><NamedCell
ss:Name="_FilterDatabase"/></Cell>
</Row>
So I have two main fields - Header 1 and Header 2, first contains id (Not unique!!!) the second - version or edition.
How is it looks in Excel:
Number Version
A001 1
A001 6
A002 2
A002 3
A003 1
I need to process all unique id's with the maximum version! Here I would like to get
A001 6
A002 3
A003 1
My xslt code is:
<xsl:template match="orig:Table" name ="Table">
<xsl:variable name="Id" select ="'Number'"/>
<xsl:element name="Declarations">
<xsl:for-each select="orig:Row">
<xsl:sort select="orig:Cell[1]/orig:Data" data-type="text" order="ascending"/>
<xsl:sort select="orig:Cell[2]/orig:Data" data-type="number" order="descending"/>
<xsl:if test="$Id!=orig:Cell[1]/orig:Data">
<xsl:call-template name="Row"> <!--Here in template "Row" all further processing will be done-->
</xsl:if>
</xsl:for-each>
</xsl:element>
</xsl:template>
At first I'm sorting them to get the list like:
Number Version
A001 6
A001 1
A002 3
A002 2
A003 1
Then I want to save every 1st header value and compare it to itself in the next row - if the value is the same, that means that it is the same record with older version and we skip it. But if value changes - this mean that we have a new record with maximum version and we should take it. Eg:
"Number" != A001 6 => we take this
A001 = A001 1 => skip
A001 != A002 3 => we take this
and so on
It would be easy to do if I could use inside "IF" construction like
variable name="Id" := orig:Cell[1]/orig:Data
But it is impossible here!
Please Help!