[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

spreadsheet xml and group-starting-with

Subject: spreadsheet xml and group-starting-with
From: Fred Christian <fredc@xxxxxxxxxxxxxx>
Date: Wed, 6 Apr 2011 16:35:02 -0700
 spreadsheet xml and group-starting-with
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.