[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Re: [xslt transform & grouping] Using the Muenchia
Hi Anton,
Here's the XSL stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:key name="by-info" match="Article" use="@info"/> <xsl:param name="filter" select="'food'"></xsl:param> <xsl:template match="Documents"> <!-- @filter='' will be true if it is there and empty or if it is not there at all) --> <xsl:apply-templates select="*[@filter='' or @filter=$filter]"/> <Documents> <xsl:for-each select="Document[@filter='' or @filter=$filter]/Article[count(.|key('by-info',@info)[@filter='' or @filter=$filter][1])=1]"> <Document name="{@info}"> <xsl:copy-of select="key('by-info',@info)[@filter=$filter]"/> </Document> </xsl:for-each> </Documents> </xsl:template> </xsl:stylesheet> The line proposed by David C. gives an exception. <xsl:for-each select="Document[@filter='' or @filter=$filter]/Article[count(.|key('by-info',@info)[@filter='' or @filter=$filter][1])=1]"> The XML looks like: <?xml version="1.0" encoding="utf-8"?> <Documents> <Document chapter="1" title="title 1" href="file1.xml" filter=""> <Article title="1.1" info="sub" filter="drink"/> <Article title="1.2" info="main" filter="food"/> </Document> <Document chapter="2" title="title 2" href="file2.xml" filter="drink"> <Article title="2.1" info="sub" filter="drink"/> <Article title="2.2" info="main" filter="food"/> </Document> </Documents> Thanx. -M From: Anton Triest <anton@xxxxxxxx> _________________________________________________________________ On the road to retirement? Check out MSN Life Events for advice on how to get there! http://lifeevents.msn.com/category.aspx?cid=Retirement
|
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
|