Subject: RE: [xsl] More Problems/Confusion Grouping with Meunchian Method From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx> Date: Tue, 11 Dec 2001 09:30:59 -0000 |
Brian, I'm not sure if I've really understood your data model or your requirements properly, but here's my attempt. (I'm a little confused because your example output lists "Desktop Email Client" under "domain 1", whereas in your data it only seems to be in domain 2). The following stylesheet: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:key name="domain" match="@domain" use="."/> <xsl:key name="tech" match="TECHNOLOGY" use="concat(., '/', @domain)"/> <xsl:template match="/"> <xsl:for-each select="//@domain[generate-id(.)=generate-id(key('domain',.)[1])]"> <!-- for each distinct domain --> Domain <xsl:value-of select="."/> <xsl:variable name="dom" select="."/> <xsl:for-each select="//TECHNOLOGY[@domain=current()] [generate-id(.)=generate-id(key('tech', concat(., '/', @domain))[1])]"> Technology <xsl:value-of select="."/> <xsl:for-each select="/PRODUCTS/PRODUCT[TECHNOLOGY[@domain=$dom and .=current()]]"> Product <xsl:value-of select="NAME"/> </xsl:for-each> </xsl:for-each> </xsl:for-each> </xsl:template> </xsl:stylesheet> produces the following output: <?xml version="1.0" encoding="utf-8"?> Domain 1 Technology Desktop Operating System Product WINDOWS XP Technology Repository Tool Product Power Designer Product ERWIN Domain 2 Technology Workstation OS Product WINDOWS XP Technology Desktop Email Client Product Outlook Technology CASE Tools Product Power Designer Product ERWIN Is this what you had in mind? Mike Kay Software AG > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of > Magick, Brian > Sent: 11 December 2001 03:07 > To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] More Problems/Confusion Grouping with Meunchian Method > > > Hi: > > I'm resorting to a post on this board as a last result of > literally days > of work trying to properly group a set of data with the > Meunchian method > with improper results. Hopefully my mistake is minor and someone can > quickly point me in the right direction. I'm sure others on this list > can attest that grouping with XSLT can be a nightmare!!! > Hopefully the > next revision of XSL brings some improvements. > > My XML: basically a list of products where each product can belong to > multiple technology areas. > > <PRODUCTS> > <PRODUCT> > <NAME>WINDOWS XP</NAME> > <TECHNOLOGY domain="1" bookmark="xp">Desktop Operating > System</TECHNOLOGY> > <TECHNOLOGY domain="2" bookmark="xp">Workstation OS</TECHNOLOGY> > </PRODUCT> > <PRODUCT> > <NAME>Outlook</NAME> > <TECHNOLOGY domain="2" bookmark="outlook">Desktop Email > Client</TECHNOLOGY> > </PRODUCT> > <PRODUCT> > <NAME>Power Designer</NAME> > <TECHNOLOGY domain="1" bookmark="pd">Repository Tool<TECHNOLOGY> > <TECHNOLOGY domain="2" bookmark="pd">CASE Tools</TECHNOLOGY> > </PRODUCT> > <PRODUCT> > <NAME>ERWIN</NAME> > <TECHNOLOGY domain="2" bookmark="erwin">CASE Tools</TECHNOLOGY> > <TECHNOLOGY domain="1" bookmark="erwin">Repository > Tool<TECHNOLOGY> > </PRODUCT> > > The list: > > I want a list of each product by Technology. Some products > will need to > be displayed twice in different technology categories. Rather than > using an "apply-templates" call that most examples of the Meunchian > Method use, I want to use a for-each loop to group each technology and > then list all of the product names that directly apply to that > technology for a given domain. > > Ex: Domain 1 > > Desktop Email Client > Outlook > Desktop Operating System > Windows XP > Repository Tool > Power Designer > > The problem: When I create the list the filter doesn't work right > because if a product exists for a technology in Domain = 1, and also > exists in another technology Domain 1 has in its list (even if not for > Domain = 1), the product lists for each technology. For > example, ERWIN > has Domain = 1 with a technology of CASE Tool. It also has a > Domain = 2 > Repository Tool. We are not interested in this second case > if we filter > by Domain = 1....BUT Power Designer exists in Domain = 1 under > Repository Tool. When we render the Domain = 1 Power Designer > Repository Tool listing it also renders the Repository Tool entry for > ERWIN although its Repository Tool entry ONLY applies to Domain 2. > Crystal clear, right? > > My stylesheet components: > > <xsl:key name="gt" match="GOVERNING_TECHNOLOGY" use="."/> > <xsl:key name="prod4gt" match="PRODUCT" use="GOVERNING_TECHNOLOGY"/> > > I use the first key "gt" to match get the list of Technology items and > then list the products referencing the 2nd key: > > <xsl:for-each > select="PRODUCTS/PRODUCT/GOVERNING_TECHNOLOGY[generate-id(.) = > generate-id(key('gt', .) > [@domain = '1'])]"> > <br/><xsl:value-of select="."/> > <xsl:for-each select="key('prod4gt',.)"> > <br/><xsl:value-of select="NAME"/> > </xsl:for-each> > </xsl:for-each> > > I can't recall how many variations of calling the 2nd key > I've tried but > I think I need to filter the 2nd key by the Domain = 1 so that I only > get the results for the right domain. Not quite sure if this is the > case and I've been unsuccessful trying to do this. > > Any pointers are appreciated before I go crazy trying to figure this > out!!! Thanks. > > > Brian Magick > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] More Problems/Confusion Group, Magick, Brian | Thread | [xsl] Re: max value, Dimitre Novatchev |
[xsl] Re: max value, Dimitre Novatchev | Date | [xsl] matching-pattern of xsl:key, "Kreyßel, Conny" |
Month |