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

Cart








