Subject: Re: [xsl] Building tables with optional data elements From: Joerg Heinicke <joerg.heinicke@xxxxxx> Date: Thu, 03 Oct 2002 12:51:04 +0200 |
<xsl:variable name="maxNoOfColumns" select="Item/NameValue[last()] [not(Name < ../following-sibling::Item/NameValue[last()]/Name)]/Name"/>
<xsl:template match="Data"> <xsl:variable name="maxNoOfColumns" select="Item/NameValue[last()] [not(Name < ../following-sibling::Item/NameValue[last()]/Name)]/Name"/> <table border="1"> <tr> <xsl:call-template name="header"> <xsl:with-param name="maxNoOfColumns" select="$maxNoOfColumns"/> </xsl:call-template> </tr> <xsl:apply-templates select="Item"> <xsl:with-param name="maxNoOfColumns" select="$maxNoOfColumns"/> </xsl:apply-templates> </table> </xsl:template>
<xsl:template match="Item"> <xsl:param name="maxNoOfColumns" select="0"/> <tr> <xsl:call-template name="row"> <xsl:with-param name="maxNoOfColumns" select="$maxNoOfColumns"/> </xsl:call-template> </tr> </xsl:template>
<xsl:template name="header"> <xsl:param name="maxNoOfColumns" select="0"/> <xsl:param name="currentNo" select="1"/> <xsl:if test="$currentNo < $maxNoOfColumns + 1"> <td>Column<xsl:value-of select="$currentNo"/></td> <xsl:call-template name="header"> <xsl:with-param name="maxNoOfColumns" select="$maxNoOfColumns"/> <xsl:with-param name="currentNo" select="$currentNo + 1"/> </xsl:call-template> </xsl:if> </xsl:template>
Good Day,
I am attempting to convert the following XML into a table. Each column is
optional and the possibility is that one or more of the column data will be
missing in each row. I need to generate the table to include all the columns for each row, with
the data in the correct column. The actual structure includes up to 22
columns with some rows having only six data entries. I have managed to build a list of column names from each row, but I have not
managed to place the correct data in the correct column when a previous
column is missing. i.e. put a blank entry when the column is missing. How do I do this?
Thanks
Grant Thiselton
Example XML: <?xml version="1.0"?> <Content> <Data> <Item> <NameValue> <Name>Column1</Name><Value>A</Value> </NameValue> <NameValue> <Name>Column2</Name><Value>B</Value> </NameValue> <NameValue> <Name>Column3</Name><Value>C</Value> </NameValue> </Item> <Item> <NameValue> <Name>Column1</Name><Value>X</Value> </NameValue> <NameValue> <Name>Column3</Name><Value>Y</Value> </NameValue> </Item> <Item> <NameValue> <Name>Column3</Name><Value>z</Value> </NameValue> </Item> </Data> </Content>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Building tables with optional, Grant Thiselton | Thread | Re: [xsl] Building tables with opti, David Carlisle |
[xsl] Re: translate() function, cha, Dimitre Novatchev | Date | Re: [xsl] Building tables with opti, David Carlisle |
Month |