Re: [xsl] Using XSL to Translate Repetitive-Node XML to Table with COLSPANs

Subject: Re: [xsl] Using XSL to Translate Repetitive-Node XML to Table with COLSPANs
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 12 Feb 2004 17:30:52 -0500
Hi Leo,

At 03:49 PM 2/12/2004, you wrote:
                        <data columnid="01" name="Feb"/>
                        <data columnid="11" name="Feb"/>
                        <data columnid="21" name="Feb"/>
                        <data columnid="31" name="Feb"/>
                        <data columnid="41" name="Y-T-D(Feb)"/>
                        <data columnid="51" name="Y-T-D(Feb)"/>
                        <data columnid="61" name="Y-T-D(Feb)"/>
                        <data columnid="71" name="Y-T-D(Feb)"/>

How easy this is depends largely on constraints on your data.


If you can be certain that data elements to be grouped in a cell not only share a @name value, but also are the only ones that have that @name value, it's not so hard:

<xsl:template match="data">
<xsl:variable name="thisname" select="@name"/>
<!-- first be sure we emit cells only for the first data element
with a given name -->
<xsl:if test="not($thisname = preceding-sibling::data/@name)">
<!-- the colspan is the count of data children of the parent with the same name -->
<td colspan="{count(../data[@name = $thisname)}">
<xsl:apply-templates select="@name"/>
<!-- the built-in default template for attributes will emit its value -->
</td>
</xsl:if>
</xsl:template>


If however you might have a situation like

  <data columnid="01" name="Feb"/>
  <data columnid="11" name="Feb"/>
  <data columnid="21" name="Feb"/>
  <data columnid="31" name="Feb"/>
  <data columnid="41" name="Y-T-D(Feb)"/>
  <data columnid="51" name="Feb"/>

... it's harder. Considerably harder (though not impossible).

So which is it?

Cheers,
Wendell




====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread