[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Distinct list problem
At 2002-01-18 14:53 +0100, Henk Meulekamp wrote:
I'm trying to get a list of id's where each id is represented once out of the xml below. Is it possible? Yes, and there are a few ways you can do it. The ouput I want is: This is a classic "grouping" problem. Two of the ways you can do it are with key tables or variables, both illustrated below using *only* XSLT 1.0 functionality and no vendor extensions. In each case one is relying on the generate-id() function to uniquely identify nodes from a set. One can use a key table for the set, or if you are using XT one can use a variable for the set. When doing grouping of subsets of the tree, using a variable for the set is often more convenient than using the key table. I hope this helps. ....................... Ken
T:\ftemp>type henk.xsl <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:key name="ids" match="ATTRIBUTEQUALITY" use="@IDTESTTYPE"/> <xsl:template match="/"> <xsl:text>using keys: </xsl:text> <xsl:for-each select="//ATTRIBUTEQUALITY [generate-id(.)= generate-id(key('ids',@IDTESTTYPE))]"> <xsl:value-of select="@IDTESTTYPE"/> <xsl:text> </xsl:text> </xsl:for-each> <xsl:text> using variables: </xsl:text> <xsl:variable name="ids" select="//ATTRIBUTEQUALITY"/> <xsl:for-each select="$ids"> <xsl:if test="generate-id(.)= generate-id($ids[@IDTESTTYPE=current()/@IDTESTTYPE])"> <xsl:value-of select="@IDTESTTYPE"/> <xsl:text> </xsl:text> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet> T:\ftemp>saxon henk.xml henk.xsl using keys: 20 21 22
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995) ISBN 0-13-065196-6 Definitive XSLT & XPath ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath ISBN 1-894049-07-1 Practical Formatting Using XSLFO XSL/XML/DSSSL/SGML/OmniMark services, books(electronic, printed), articles, training(instructor-live,Internet-live,web/CD,licensed) Next public training: 2002-01-18,02-11,12,13,15,18,21, - 03-04,05,06,08,11,04-08,09,10,12,05-14,15,06-04,07 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|