[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

How to account for optional elements in a table in XSL?

Subject: How to account for optional elements in a table in XSL?
From: Francois Belanger <francois@xxxxxxxxxxx>
Date: Thu, 23 Apr 98 12:38:49 -0400
element td
I'm parsing an XML file which has optional elements. I want to produce a 
table from the rows but need to check for the presence of the optional 
elements and put appropriate empty cells where needed.

The way I found to keep the columns in order is with multiple rules with 
importance attributes and select in actions. It's a bit busy and I'm 
wondering, since this is a problem that often comes up, if it's the best 
way to handle this. 

Here's the simplified XSL rules, for a table with 5 columns, elements 3 4 
optional:

<!-- cell 3 4 missing -->
<rule importance="1">
  <target-element type="row">
  	<element type="cell_1"/>
  	<element type="cell_2"/>
  	<element type="cell_5"/>
   </target-element>
	<TR valign="top">
	<TD>
		<select-elements>
			<target-element type="cell_1"/>
		</select-elements>
	</TD>
	<TD>
		<select-elements>
			<target-element type="cell_2"/>
		</select-elements>
	</TD>
	<TD></TD>
	<TD></TD>	
	<TD  align="right">
		<select-elements>
			<target-element type="cell_5"/>
		</select-elements>
	</TD>
	</TR>
</rule>

<!-- cell  4 missing -->
<rule importance="2">
  <target-element type="row">
  	<element type="cell_1"/>
  	<element type="cell_2"/>
  	<element type="cell_3"/>
  	<element type="cell_5"/>
   </target-element>
	<TR valign="top">
	<TD>
		<select-elements>
			<target-element type="cell_1"/>
		</select-elements>
	</TD>
	<TD>
		<select-elements>
			<target-element type="cell_2"/>
		</select-elements>
	</TD>
	<TD>
		<select-elements>
			<target-element type="cell_3"/>
		</select-elements>
	</TD>
	<TD></TD>	
	<TD  align="right">
		<select-elements>
			<target-element type="cell_5"/>
		</select-elements>
	</TD>
	</TR>
</rule>

<!-- cell 3 missing -->
<rule importance="2">
  <target-element type="row">
  	<element type="cell_1"/>
  	<element type="cell_2"/>
  	<element type="cell_4"/>
  	<element type="cell_5"/>
   </target-element>
	<TR valign="top">
	<TD>
		<select-elements>
			<target-element type="cell_1"/>
		</select-elements>
	</TD>
	<TD>
		<select-elements>
			<target-element type="cell_2"/>
		</select-elements>
	</TD>
	<TD></TD>	
	<TD>
		<select-elements>
			<target-element type="cell_4"/>
		</select-elements>
	</TD>
	<TD  align="right">
		<select-elements>
			<target-element type="cell_5"/>
		</select-elements>
	</TD>
	</TR>
</rule>

<!-- no cell missing -->
<rule importance="3">
  <target-element type="row">
  	<element type="cell_1"/>
  	<element type="cell_2"/>
  	<element type="cell_3"/>
  	<element type="cell_4"/>
  	<element type="cell_5"/>
   </target-element>
	<TR valign="top">
	<TD>
		<select-elements>
			<target-element type="cell_1"/>
		</select-elements>
	</TD>
	<TD>
		<select-elements>
			<target-element type="cell_2"/>
		</select-elements>
	</TD>
	<TD>
		<select-elements>
			<target-element type="cell_3"/>
		</select-elements>
	</TD>
	<TD>
		<select-elements>
			<target-element type="cell_4"/>
		</select-elements>
	</TD>
	<TD  align="right">
		<select-elements>
			<target-element type="cell_5"/>
		</select-elements>
	</TD>
	</TR>
</rule>

Now, this is just a 5 column table with 2 optional cells, imagine if all 
cell elements were optional or more columns were added.

There's got to be a better way... Thanks for any suggestion!




Francois Belanger
Sitepak, Bringing Internet Business into Focus
http://www.sitepak.com



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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.