[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: spreadsheet xml and group-starting-with
please see below, near 'group-starting-with'
On 2011-04-07 01:35, Fred Christian wrote: 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. 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"/> This is a pattern. You have to specify at which element the grouping should start, just as you'd specify a template's match: group-starting-with="ss:Row[not(ss:Cell[1]/@ss:Index)]"> <group> <xsl:copy-of select="current-group()"/> </group> </xsl:for-each-group> </xsl:template> </xsl:stylesheet> --------------------------------------------------------------------- End My xslt 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. --------------------------------------------- A complete stylesheet with @Index-Cell expansion may look like: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:saxon="http://saxon.sf.net/" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html4="http://www.w3.org/TR/REC-html40" xmlns:html="http://www.w3.org/1999/xhtml" exclude-result-prefixes="saxon xs o x ss html4 html" > <xsl:output method="xml" indent="yes" saxon:suppress-indentation="term definition image reference extrainfo" /> <xsl:template match="/"> <xsl:apply-templates select="ss:Workbook/ss:Worksheet[1]/ss:Table"/> </xsl:template> <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:Row[not(ss:Cell[1]/@ss:Index)]"> <group> <xsl:apply-templates select="current-group()" mode="expand-indexed-cells" /> </group> </xsl:for-each-group> </xsl:template> <xsl:template match="ss:Cell[@ss:Index]" mode="expand-indexed-cells" > <xsl:variable name="last-index-item" select="preceding-sibling::ss:Cell[@ss:Index][1]" as="element(ss:Cell)?"/> <xsl:variable name="last-pos" select="if ($last-index-item) then count(preceding-sibling::ss:Cell[. >> $last-index-item]) + $last-index-item/@ss:Index else count(preceding-sibling::ss:Cell)" /> <xsl:for-each select="( (($last-pos + 1) cast as xs:integer) to ((@ss:Index - 1) cast as xs:integer))"> <Cell xmlns="urn:schemas-microsoft-com:office:spreadsheet" /> </xsl:for-each> <xsl:copy> <xsl:copy-of select="@* except @ss:Index" /> <xsl:apply-templates mode="#current" /> </xsl:copy> </xsl:template> <xsl:template match="@* | *" mode="#all" priority="-20"> <xsl:copy> <xsl:apply-templates select="@* | node() | comment()" mode="#current"/> </xsl:copy> </xsl:template> </xsl:stylesheet> -Gerrit
Registergericht / Commercial Register: Amtsgericht Leipzig Registernummer / Registration Number: HRB 24930 Geschdftsf|hrer: Gerrit Imsieke, Svea Jelonek, Thomas Schmidt, Dr. Reinhard Vvckler
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|