[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?
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|