[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: generate 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
|
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
|