xsl-list
[Top] [All Lists]

[xsl] spreadsheet xml and group-starting-with

2011-04-06 18:35:39
I have a MS spreadsheet xml that I will be transforming into an html table.
I need to use group-starting-with to group multiple rows into one
based on empty cells in the first column.

ex.  If I have

Col A, Col b, Col c
1a, 1b, 1c
   ,  2b, 2c
   ,      ,3c
4a,4b,4c
    ,    ,5c
---
I will eventually create a html table with two rows and three columns.
For now I am trying to just get grouping to work, but I got stuck.
Just when I thought I had for-each-group figured out I get stumped again.
Can you get me going in the right direction?

Sample MS Xml
---------------------------------------------------------------------
 <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
 <Worksheet>
    <Table>
      <Row>
        <Cell><Data ss:Type="String">1a</Data></Cell>
        <Cell><Data ss:Type="String">1b</Data></Cell>
        <Cell><Data ss:Type="String">1c</Data></Cell>
      </Row>
      <Row>
        <Cell ss:Index="2"><Data ss:Type="String">2b</Data></Cell>
        <Cell><Data ss:Type="String">2c</Data></Cell>
      </Row>
      <Row>
        <Cell ss:Index="3"><Data ss:Type="String">3c</Data></Cell>
      </Row>
      <Row>
        <Cell><Data ss:Type="String">4a</Data></Cell>
        <Cell><Data ss:Type="String">4b</Data></Cell>
        <Cell><Data ss:Type="String">4c</Data></Cell>
      </Row>
      <Row>
        <Cell ss:Index="3"><Data ss:Type="String">5c</Data></Cell>
      </Row>
    </Table>
  </Worksheet>
</Workbook>
---------------------------------------------------------------------
End Sample MS Xml
Notice, they optimize cells by using ss:Index="" when they skip cells.
And leave that attribute out when they don't. I figured this would be
a good thing to group on.

My xslt
---------------------------------------------------------------------
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<xsl:output encoding="iso-8859-1" method="xml" indent="yes"/>

<xsl:template match="ss:Workbook">
<body>
     <xsl:apply-templates select="ss:Worksheet[1]/ss:Table"/>
</body>
</xsl:template>

<xsl:template match="ss:Table">
        <xsl:for-each select="ss:Row">
                <xsl:if test="ss:Cell[1][not(@ss:Index)]"><data>grouping 
row</data></xsl:if>
        </xsl:for-each>
<data>show them grouped now</data>
        <xsl:for-each-group select="ss:Row"
group-starting-with="ss:Cell[1][not(@ss:Index)]">
                <group>
                <xsl:copy-of select="current-group()"/>
                </group>
        </xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
---------------------------------------------------------------------
End My xslt


In my output, I correctly get two "<data>grouping row</data>" nodes.
But I only get one <group>{stuff}</group>
I would have expected two.

For this example, I want output that looks something like the following.
It doesn't have to be exact, but if I can get two groups with the
implied cell data, then I can probably go from there, I hope.
---------------------------------------------
<group>
      <Row>
        <Cell><Data ss:Type="String">1a</Data></Cell>
        <Cell><Data ss:Type="String">1b</Data></Cell>
        <Cell><Data ss:Type="String">1c</Data></Cell>
      </Row>
      <Row>
        <Cell ss:Index="2"><Data ss:Type="String">2b</Data></Cell>
        <Cell><Data ss:Type="String">2c</Data></Cell>
      </Row>
      <Row>
        <Cell ss:Index="3"><Data ss:Type="String">3c</Data></Cell>
      </Row>
</group>
<group>
      <Row>
        <Cell><Data ss:Type="String">4a</Data></Cell>
        <Cell><Data ss:Type="String">4b</Data></Cell>
        <Cell><Data ss:Type="String">4c</Data></Cell>
      </Row>
      <Row>
        <Cell ss:Index="3"><Data ss:Type="String">5c</Data></Cell>
      </Row>
</group>
------------------------------------------


Thanks
Fred

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>