Subject: Re: [xsl] Creating Columnar Table format with XML data From: Kenneth Stephen <marvin.the.cynical.robot@xxxxxxxxx> Date: Sun, 14 Aug 2005 10:17:07 -0500 |
Maria, Example implementation : <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:exsl-common="http://exslt.org/common" extension-element-prefixes="exsl-common"> <xsl:variable name="var"> <column title="Capital Markets"> <bullet ID="1"> <tip>This is the first tip for Capital Markets.</tip> </bullet> <bullet ID="2"> <tip>This is the second tip for Capital Markets</tip> </bullet> </column> <column title="Environment Industry and Company Markets"> <bullet ID="3"> <tip>This is the first tip for Environment, Industry and Company Markets.</tip> </bullet> </column> </xsl:variable> <xsl:template match="/"> <xsl:variable name="input-data" select="exsl-common:node-set($var)" /> <table> <tr> <xsl:apply-templates select="$input-data" mode="titles" /> </tr> <xsl:choose> <xsl:when test="count($input-data/column[1]/bullet) > count($input-data/column[2]/bullet)"> <xsl:for-each select="$input-data/column[1]/bullet"> <tr> <td><xsl:apply-templates select="." /></td> <xsl:variable name="current-pos" select="count(preceding-sibling::bullet) + 1" /> <td><xsl:apply-templates select="$input-data/column[2]/bullet[$current-pos]" /></td> </tr> </xsl:for-each> </xsl:when> <xsl:otherwise> <xsl:for-each select="$input-data/column[2]/bullet"> <tr> <td><xsl:apply-templates select="." /></td> <xsl:variable name="current-pos" select="count(preceding-sibling::bullet) + 1" /> <td><xsl:apply-templates select="$input-data/column[1]/bullet[$current-pos]" /></td> </tr> </xsl:for-each> </xsl:otherwise> </xsl:choose> </table> </xsl:template> <xsl:template match="column" mode="titles"> <td><xsl:value-of select="@title" /></td> </xsl:template> </xsl:stylesheet> In your case, you are probably using a separate input file for your data, you wont need to use the node-set functions like I have. Regards, Kenneth On 8/13/05, Maria Leggett <maria@xxxxxxxxxxxxxx> wrote: > I have an xml file that I need to create into a columnar table format. I > can't figure out how to group the data to display in a column when not all > the column rows cells will contain data. I am using XSL 1.0 > > sample xml is: > > <column title="Capital Markets"> > <bullet ID="1"> > <tip>This is the first tip for Capital Markets.</tip> > </bullet> > <bullet ID="2"> > <tip>This is the second tip for Capital Markets</tip> > </bullet> > </column> > <column title="Environment Industry and Company Markets"> > <bullet ID="3"> > <tip>This is the first tip for Environment, Industry and Company > Markets.</tip> > </bullet> > </column> > > The html output should look something like this: > <table> > <tr> > <td>Capital Markets</td> > <td>Environment, Industry and Company Markets</td> > </tr> > <tr> > <td>This is the first tip for Capital Markets</td> > <td>This is the first tip for Environment, Industry and Company Markets</td> > </tr> > <tr> > <td>This is the second tip for Capital Markets</td> > > <td></td> > </tr> > </table> > > Thank you for any help.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Creating Columnar Table f, Mukul Gandhi | Thread | [xsl] format-number in Saxon 8.5, Manfred Staudinger |
Re: [xsl] Creating Columnar Table f, Mukul Gandhi | Date | RE: [xsl] How to sort attribute?, Michael Kay |
Month |