Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - How do I extract a repeating attribute value out to display it only once (using XSLT 1.0). >Thread Next - Re: How do I extract a repeating attribute value out to display itonly once (using XSLT 1.0). Re: How do I extract a repeating attribute value out to display it only once (using XSLT 1.0).To: NULL Date: 3/4/2008 3:26:00 PM mark4asp wrote: > Apologies, I just can't get my head around xslt but I need to do this. > > I have an xml file with two attributes per product. One of the > attributes repeats to produce several groups (3 in the example, grouped > by region). How can I select this repeating attribute out as a header > column in a table with the other attribute as in a data column. (see > example html). XSLT 1.0 solutions only please (or whatever is > compatible with current major browser parsers [FF, IE6, IE7, Opera, > Safari]). It is a grouping problem, solved in XSLT 1.0 using Muenchian grouping: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" indent="yes"/> <xsl:key name="by-region" match="product" use="@region"/> <xsl:template match="sales"> <html lang="en"> <head> <title>Example</title> </head> <body> <table> <tbody> <xsl:apply-templates select="product[generate-id() = generate-id(key('by-region', @region)[1])]" mode="th"/> </tbody> </table> </body> </html> </xsl:template> <xsl:template match="product" mode="th"> <tr> <th><xsl:value-of select="@region"/></th> </tr> <xsl:apply-templates select="key('by-region', @region)" mode="td"/> </xsl:template> <xsl:template match="product" mode="td"> <tr> <td><xsl:value-of select="@item"/></td> </tr> </xsl:template> </xsl:stylesheet> -- Martin Honnen http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
