Subject: RE: [xsl] generate unknow table From: "Gareth Sylvester-Bradley" <gareth.sbradley@xxxxxxxxxxxxxxx> Date: Mon, 11 Jun 2001 21:45:47 +0100 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] generate unknow table, John Wang | Thread | RE: [xsl] generate unknow table, John Wang |
RE: [xsl] generate unknow table, John Wang | Date | Re: [xsl] XSLT Editor, xml startkabel |
Month |