RE: [xsl] fill in a table with dynamic header at correct place

Subject: RE: [xsl] fill in a table with dynamic header at correct place
From: Rene de Vries <RdVries@xxxxxxxxxxx>
Date: Wed, 18 Jul 2001 11:49:10 +0200
Jan,

I think the XML you have to work on should be build more efficient, but I 
don't know if you have anything to say about it.
Since the only thing you can rely on is the <definitions>, the only thing I 
can think of is this, but I hope that somebody has a better solution:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:output method="html" indent="yes"/>

	<xsl:template match="SPStruct">
		<html>
			<body>
				<table border="1">
					<xsl:apply-templates select="definitions"/>
				</table>
			</body>
		</html>
	</xsl:template>

	<xsl:template match="definitions">
		<!-- head first -->
		<th>
			<tr>
				<xsl:for-each select="col">
					<td>
						<xsl:value-of select="@name"/>
					</td>
				</xsl:for-each>
			</tr>
		</th>

		<!-- now search the data -->
		<xsl:for-each select="/SPStruct/data/row">
			<xsl:variable name="CurRow" select="position()"/>
			<tr>
				<xsl:for-each select="/SPStruct/definitions/col">
					<xsl:variable name="CurCol" select="@name"/>
					<xsl:variable name="CurData" 
select="/SPStruct/data/row[$CurRow]/col[@name=$CurCol]"/>
					<td>
						<xsl:choose>
							<xsl:when test="$CurData">
								<xsl:value-of select="$CurData"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:text>&#160;</xsl:text>
							</xsl:otherwise>
						</xsl:choose>
					</td>
				</xsl:for-each>
			</tr>
		</xsl:for-each>
		
	</xsl:template>

</xsl:stylesheet>

Greetings Rene
   { @   @ }
        ^
      \__/

"You don't need eyes to see, you need vision!"

-----Oorspronkelijk bericht-----
Van:	Jan Weiss [SMTP:jweiss@xxxxxxxxxxxxxxxxxx]
Verzonden:	woensdag 18 juli 2001 8:50
Aan:	xsl-list
Onderwerp:	[xsl] fill in a table with dynamic header at correct place

hi all,

two problems:

First: How can I get the -name- of each attribute which exists in an xml
file (I need the name and not the value, because I have to build the header
of a table by the attribute names, which are changing from xml file to xml
file!!)

Second:
I have a big problem to fill in dynamic tables. Header and number of cols
are always different. I read the header of the table out of
/SPStruct/definitions/col/@name !
I want to put all stuff of ../data/row/col at the right place in the table,
but this is the problem: if one attribute is empty, it does not appear in
the xml file so I am not able to simply write the data in a row.
I hope my explanation was not toooo bad and I hope somebody could HELP ME.

thanks


jan weiss

p.s.: my output looks like this:


Part_Name	NOMINAL_SIZE	SERIES	A	B	T .... BCT-ITEM-ID	BCT-ITEM-REV ...

shdfkg	lshygk		hygkhf	khg	kjh	kjh	  lhlhlj		 NOTHING


there is no connection between header and content.




<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet href="bct_spreadsheet.xsl" type="text/xsl" ?>

<!DOCTYPE bct-spreadsheet-definition SYSTEM "bct_spreadsheet.dtd" >

<SPStruct template="fgdhfjhfd">
 <definitions>
  <col order="1" alias="" type="A" min="" max="" name="Part_Name" /> <!--
each attribute name should be compared with ../data/row/@name then if true
write data into col of table else fill in col with blank -->
  <col order="2" alias="" type="N" min="" max="" name="NOMINAL_SIZE"
visible="I" />
  <col order="3" alias="series" min="" max="" name="SERIES" color="#ae1234"
/>
  <col order="4" alias="" type="N" min="" max="" name="A" color="#ffff7f" 
/>
  <col order="5" alias="" type="N" min="" max="" name="B" visible="I" />
  <col order="6" alias="" type="N" min="" max="" name="T" />
  <col order="7" alias="" min="" max="" name="BCT-BOM-REL" />
  <col order="8" alias="german" min="" max="" name="BCT-DESC1-DE" />
  <col order="9" alias="" min="" max="" name="BCT-DESC1-EN" />
  <col order="10" alias="" min="" max="" name="BCT-DESC2-DE" />
  <col order="11" alias="" min="" max="" name="BCT-DESC2-EN" />
  <col order="12" alias="" min="" max="" name="BCT-ITEM-ID" />
  <col order="13" alias="" min="" max="" name="BCT-ITEM-REV" />
  <col order="14" alias="" min="" max="" name="BCT-ITEM-VAR" />
  <col order="15" alias="" min="" max="" name="BCT-MATERIAL" />
  <col order="16" alias="" min="" max="" name="BCT-MATERIAL-NO" />
  <col order="17" alias="" min="" max="" name="BCT-QUANTITY-UNIT" />
  <col order="18" alias="" min="" max="" name="BCT-WEIGHT" />
  <col order="19" alias="" min="" max="" name="BCT-WEIGHT-UNIT" />
  <col order="20" alias="" min="" max="" name="SECTION-COMPONENT" />
  <col order="21" alias="" min="" max="" name="$DESCRIPTION" />
 </definitions>
 <data>
  <row>
   <col name="Part_Name" >ghj</col>
   <col name="NOMINAL_SIZE" >0.06</col>
   <col name="SERIES" >N</col>
   <col name="A" >hj</col>
   <col name="B" >gdh5</col>
   <col name="T" >dg25</col>
   <col name="BCT-BOM-REL" >1</col>
   <col name="BCT-DESC1-DE" >rhfhfdh</col>
   <col name="BCT-DESC1-EN" >djdhgjdhjd</col>  <!-- in this example and 
they
should be blank output -->
   <col name="BCT-QUANTITY-UNIT" >piece</col>
   <col name="SECTION-COMPONENT" >NO</col>
   <col name="$DESCRIPTION" >fgjgf</col>
  </row>
  <row>
   <col name="Part_Name" >fgjggfj</col>
   <col name="NOMINAL_SIZE" >0.06</col>
   <col name="SERIES" >R</col>
   <col name="A" >0fgj8</col>
   <col name="B" >0gh</col>
   <col name="T" >gfj5</col>
   <col name="BCT-BOM-REL" >1</col>
   <col name="BCT-DESC1-DE" >fghjf</col>
   <col name="BCT-DESC1-EN" >gfjr</col>
   <col name="BCT-QUANTITY-UNIT" >piece</col>
   <col name="SECTION-COMPONENT" >NO</col>
   <col name="$DESCRIPTION" >gfjgfhj</col>
  </row>
</data>
</SPStruct>







<xsl:template match="data">

  <TABLE BGCOLOR="#FFFFFF" BORDER="0" CELLSPACING="2" CELLPADDING="2"
ALIGN="left">

    <TR ALIGN="left" BGCOLOR="#9C1029">
	<font face="Arial" size="+1" color="#FFFFFF"><b>kgkgkh</b></font>
	</TR>

    	<TR BGCOLOR="ffffdd">

  <xsl:apply-templates  select="/SPStruct/definitions/col" mode="index"/>
    	</TR>
  <xsl:apply-templates/>
  </TABLE>
</td>
</tr>
</xsl:template>

<xsl:template match="/SPStruct/definitions/col"  mode="index">

     <TD><xsl:value-of select="@name"/></TD>  <!-- header of the table -->

</xsl:template>



<!-- *** row *** -->

 <xsl:template match="/SPStruct/data/row>

  <TR BGCOLOR="FFFFFF" class="odd">

    <xsl:apply-templates mode="ind" />

  </TR>

</xsl:template>




<xsl:template match="/SPStruct/data/row/col" mode="ind">

<xsl:choose>
	<xsl:when test="@name=//definitions/col/@name">  <!-- I think the error
must be here -->

		<TD><xsl:value-of select="." /></TD> <!-- only write data to table if
@name suites to actual header of actual columnn -->

	</xsl:when>

<xsl:otherwise><td> sfidsgoisdg </td></xsl:otherwise>  <!-- only to fill
empty cols -->

</xsl:choose>

</xsl:template>

</xsl:stylesheet>


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


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


Current Thread