Subject: Re: [xsl] problem of repetition From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Wed, 31 Jan 2001 12:26:40 +0000 |
Hi Kapil, > i am facing one problem.the problem is that in report i am getting > same project name again and again and the records are also in a > repetition. but i have solved the problem of grouping.means to > separate the data of projects and the same project data in a single > table.but this project name is repeating and its records are also > repetiting. It looks as though you're trying to use the Muenchian method without really understanding how it works at all. >From your stylesheet, I guess that your input looks something like: <rowset> <row><PROJECT_ID value="..." /><TASK_NAME value="..." /></row> <row><PROJECT_ID value="..." /><TASK_NAME value="..." /></row> ... </rowset> and that you want to have groups of rows according to the 'value' attribute of their PROJECT_ID child element. First, the key. The key has to match the things that you want to group and the 'use' attribute has to be set to the thing that you want to group them by. You want to group row elements, and you want to group them by the 'value' attribute of their PROJECT_ID child element, so the correct key looks like: <xsl:key name="manish" match="row" use="PROJECT_ID/@value" /> If you want to apply templates to the first row in each group (and you're currently on the rowset element), you can use the instruction: <xsl:apply-templates select="row[generate-id() = generate-id(key('manish', PROJECT_ID/@value)[1])]" /> Applying templates to the first of each group of rows is how you get the output for that group. You want to get the output for the group within the body of the HTML, so this instruction needs to be placed within the static HTML that you're generating: <xsl:template match="rowset"> <html> <head> <title>Ptss</title> <link rel="stylesheet" href="../../Content_Files/Form.css" /> </head> <body> <!-- apply templates to the first row in each group --> <xsl:apply-templates select="row[generate-id() = generate-id(key('manish', PROJECT_ID/@value)[1])]" /> </body> </html> </xsl:template> [Note: I've taken out the meta element that was setting the content type as this is automatically added for you by the XSLT processor if you're using HTML as the output method. If you want to set the character encoding to iso-8859-1, then you should use the xsl:output element to do this: <xsl:output method="html" encoding="iso-8859-1" />] Now, within the body of the HTML, we're applying templates to one row element per group (the first in each group). To add the content for that group, you should have a template that matches a row and adds the relevant content. You can get the other rows in the group that the row you're looking at belongs to using the key again: key('manish', PROJECT_ID/@value) So the template should look something like: <!-- this template only matches one row per group --> <xsl:template match="row"> <xsl:value-of select="PROJECT_ID/@value" /> <!-- iterate over all the rows in the group --> <xsl:for-each select="key('manish', PROJECT_ID/@value)"> <xsl:sort select="TASK_NAME/@value" /> <p><xsl:value-of select="TASK_NAME/@value" /></p> </xsl:for-each> </xsl:template> I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] problem of repetition, kapil | Thread | [xsl] problem of repetition, kapil |
Re: [xsl] how can check whether an , Eric van der Vlist | Date | [xsl] Advise on xsl usage producing, viewga |
Month |