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

Re: generate unknow table

Subject: Re: generate unknow table
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Tue, 12 Jun 2001 15:16:41 -0400
unknow table
[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.

Enjoy.

Tom P

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<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'
 select='display/title/field[@id="sel"]/@ND'/>

<!--////// 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'/>
  </table>
</html>
</xsl:template>

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

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


<!--/////// 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'
         select='$row/*[name()=$field]'/>
  <xsl:variable name='flag' select='$cell/@*[$display-flag]'/>
  <td><xsl:if test='not($flag)
           or $flag="on"'>
        <xsl:value-of select='$cell'/>
   </xsl:if>
  </td>
 </xsl:for-each>
</xsl:template>

</xsl:stylesheet>


 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.