Subject: RE: [xsl] generate unknow table From: "John Wang" <jwang@xxxxxxxxxxx> Date: Mon, 11 Jun 2001 17:12:55 -0500 |
Thanks a lot. I really appreciate your quick response. It seems solve my problem. As you have seen, in my xml, the <title> element is generated from display file, which can be pre-generated; But the <data> element is generated dynamically. I have to, somehow, merge these two part together to make them one <display> element. Which fields should be displayed is determined at run time. I have a flag inside in <data> element, which was not shown in the list just for simplicity. In the real case, something like: <data> <record> <sel flag80="off">001</sel> <sflbr>002</sflbr> ... </record> ... </data> this will tell the xsl that the field <sel> should not be displayed. fortunately, only <sel> element has this attribute. and in the <title> element, we have something like: <title> <sel flag="flag80">Selection</sel> ... </title> which tells the XSL it should look for "flag80" in the same field in the dynamic generated <record> element to determine whether this field shall be displayed or not. One more thing, we have actually some other flags too. Do you still think it is possible to use XSLT? Or you think we should change the original xml format? Change original xml format for us is very hard, simply because the display file has been using a lot, and its format is fixed. Million thanks to you, Gareth! -John -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Gareth Sylvester-Bradley Sent: Monday, June 11, 2001 3:46 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: [xsl] generate unknow table I've no doubt that there's a complicated solution that will cope with the generic case which your XML seems to suggest might occur - e.g. re-ordering of columns in the data records, additional columns being specified or certain columns missing. However, I'm wondering whether your format is really as general purpose as this? There is a trivial solution if you know that the *order* of the field nodes in the title match the order of the nodes in the data records (and that none are missing). Simply <xsl:template match="data"> <xsl:for-each select="record"> <tr> <xsl:for-each select="*"> <td> <xsl:value-of select="."/> </td> </xsl:for-each> </tr> </xsl:for-each> </xsl:template> Of course, as always, the for-each loops *might* be clearer re-written as a call to apply-templates with separate templates for each case. But tell us how general your format is.... Hope that helps, Gareth -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of John Wang Sent: 11 June 2001 21:26 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: [xsl] generate unknow table Hi, All I have posted this question few days ago. It seems no body even give a try to answer this question. Could someone tell me this is impossible in XSLT? Or my question is not clear? Thanks a lot in advance. Here is my xml: <?xml version="1.0"?> <display> <title> <field id="sflbr">Br</field> <field id="sflcyc">Cycle</field> <field id="sfsts">P/I Status Description</field> <field id="pidate">P/I Date</field> </title> <data> <record> <sel>12</sel> <sflbr>001</sflbr> <sflcyc>200</sflcyc> <sfsts>This is a description</sfsts> <pidate>06-02-01</pidate> </record> <record> <sel>11</sel> <sflbr>002</sflbr> <sflcyc>210</sflcyc> <sfsts>This is a description too</sfsts> <pidate>06-11-01</pidate> </record> </data> </display> Here is my xsl: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="/"> <html> <body> <table border="1"> <xsl:apply-templates select="display/title"/> <xsl:apply-templates select="display/data"/> </table> </body> </html> </xsl:template> <xsl:template match="title"> <tr> <xsl:for-each select="field"> <td> <xsl:value-of select="."/> </td> </xsl:for-each> </tr> </xsl:template> <xsl:template match="data"> <xsl:for-each select="record"> <tr> <td> <xsl:value-of select="sflbr"/> </td> <td> <xsl:value-of select="sflcyc"/> </td> <td> <xsl:value-of select="sfsts"/> </td> <td> <xsl:value-of select="pidate"/> </td> </tr> </xsl:for-each> </xsl:template> </xsl:stylesheet> If you do the XSL transform, you will get the result I want to get. The problem is, when I write the XSL, I don't know the columns I want to display, until I read the coming XML. How can I get the field name such as sflbr, sflcyc, sfsts, pidata from the display/title/field@id? Thanks a lot. -John XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list ************************************************************************* The information contained in this message or any of its attachments may be privileged and confidential and intended for the exclusive use of the addressee. If you are not the addressee any disclosure, reproduction, distribution or other dissemination or use of this communication is strictly prohibited ************************************************************************** XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] generate unknow table, Gareth Sylvester-Bra | Thread | RE: [xsl] generate unknow table, John Wang |
[xsl] Alternating Row Colors using , Kevin Shallow | Date | RE: [xsl] Solution for word wrappin, Clapham, Paul |
Month |