Re: [xsl] generate unknow table

Subject: Re: [xsl] generate unknow table
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Tue, 12 Jun 2001 15:16:41 -0400
[John Wang]

> 1) yes, if there is a field with id="sel" in <title> element,
> there must be a element <sel> in the record. no missing field.
> 2) no. the order is determined by the title. in the record the order may
> vary.
> 3) Yes. the <table> element is the <table> tag in HTML. The order in the
> table is
>    determined by the order of the <field> element in the <title> element.
> Actually, these are two parts. The <title> element is
> pre-generated statically from a display control file. and
> <data> is generated dynamically from database. whether the certain
> field is displayed or not is determined by the "flag80" attribute
> at run time.
> If someone can help, that will be great, if not, could someone
> tell me it is impossible for XSLT to do this kind of job?

Here is your style sheet.  Notice that I have assumed that you don't know
the name of the flag beforehand (it might be something else besides
'flag80').  I assumed this because the value is supplied as an attribute, so
it might be subject to change. Also note that in your example, both rows
have flag80='off'.  I have tested this stylesheet with all combinations of
'on' and 'off' and it works.

This transform works with msxml3, Saxon, and 4xslt.


Tom P

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
<xsl:output method='html'/>

<!-- ////// Get list of field names ////////-->
<xsl:variable name='fields' select='display/title/field/@id'/>

<!--/////// Get name of flag ////////-->
<xsl:variable name='display-flag'

<!--////// Main Template ////////-->
<xsl:template match="/display">
<html><title>XSl Example for Unknown "sel" Flag Name</title>
  <table border='1'>
   <xsl:call-template name='headers'/>
   <xsl:call-template name='data'/>

<!--/////// Row headers //////-->
<xsl:template name='headers'>
 <tr><xsl:for-each select='$fields'>
  <th><xsl:value-of select='.'/></th>

<!--/////// Table body //////-->
<xsl:template name='data'>
 <xsl:for-each select='data/record'>
  <tr><xsl:call-template name='get-record'/></tr>

<!--/////// Format each row ////////-->
<xsl:template name='get-record'>
 <xsl:variable name='row' select='.'/>
 <xsl:for-each select='$fields'>
  <xsl:variable name='field' select='../@id'/>
  <xsl:variable name='cell'
  <xsl:variable name='flag' select='$cell/@*[$display-flag]'/>
  <td><xsl:if test='not($flag)
           or $flag="on"'>
        <xsl:value-of select='$cell'/>


 XSL-List info and archive:

Current Thread