Subject: Re: [xsl] Doublet From: Sven Waibel <sven.waibel@xxxxxxxx> Date: Tue, 15 Mar 2005 15:55:05 +0100 |
Hi, thanks so much, it works. Sven Pieter Reint Siegers Kort wrote: > Hi Sven, > > You're dealing with a typical grouping problem, in XSLT this is done using > xsl:key, generate-id(), and key(); try this stylesheet on your XML (I've > used HTML as the output): > > <?xml version='1.0'?> > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > <xsl:key name="ids" match="*[@id]" use="@id" /> > > <xsl:template match="/tc"> > <table> > <tr><th>Id</th><th>Name</th></tr> > <xsl:apply-templates select="pc" /> > </table> > </xsl:template> > > <xsl:template match="pc"> > <xsl:apply-templates > select="*[@id and generate-id(.)=generate-id(key('ids', @id))]" /> > </xsl:template> > > <xsl:template match="*[@id]"> > <tr> > <!-- first column is the value of the id attribute --> > <td><xsl:value-of select="@id" /></td> > <!-- second column is the name --> > <td><xsl:value-of select="@name" /></td> > </tr> > </xsl:template> > > </xsl:stylesheet> > > It outputs: > > <?xml version='1.0' ?> > <table> > <tr><th>Id</th><th>Name</th></tr> > <tr><td>1</td><td>10000</td></tr> > <tr><td>2</td><td>10001</td></tr> > <tr><td>3</td><td>1</td></tr> > </table> > > I've tested it with StylusStudio 6 Release 2. > > Cheers, > <prs/> > > -----Original Message----- > From: Sven Waibel [mailto:sven.waibel@xxxxxxxx] > Sent: Martes, 15 de Marzo de 2005 07:01 a.m. > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] Doublet > > Hi everybody, > > i got following result: > > 10000 > 10001 > 1 > 10000 > > I want to have: > > 10000 > 10001 > 1 > > I don't want to get doublets. > > Does anybody know something about it? > > Thanks in advance and best regards > Sven > > > my xsl: > ---------------------------------- > <xsl:template match="pc"> > <xsl:for-each select="error-id"> > <fo:block> > <xsl:value-of select="@name"/> > </fo:block> > </xsl:for-each> > </xsl:template> > > --------------------------------- > my xml: > --------------------------------- > <tc> > <pc> > <error-id id="1" name="10000" /> > <error-id id="2" name="10001"/> > </pc> > <pc> > <error-id id="3" name="1" /> > <error-id id="1" name="10000"/> > </pc> > </tc>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Doublet, Pieter Reint Siegers | Thread | [xsl] Error in XPath expression wit, António Mota |
RE: [xsl] Doublet, Pieter Reint Siegers | Date | [xsl] Error in XPath expression wit, António Mota |
Month |