[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Filtering when grouping by Meunchian Method
Hi Brian, > Does anyone know how to filter the result set given by sorting with > the Meunchian method? I would like to filter the following based on > an attribute of GOVERNING_TECHNOLOGY called GTBookmark. Ideally you'd be able to set up the key such that it only matched those GOVERNING_TECHNOLOGY elements whose GTBookmark attribute was equal to whatever value you're interested in, e.g.: <xsl:key name="gt" match="GOVERNING_TECHNOLOGY[@GTBookmark = 'foo']" use="." /> However, it looks as though you're getting the value that you want GTBookmark to match through a variable of some description, which means that you can't use it when you set up the key. So instead you need to define the general key that you have, and then filter the result of calling the key so that it only includes the GOVERNING_TECHNOLOGY elements that you're interested in. When you do the initial grouping, you need something like: <xsl:apply-templates select="PRODUCT/GOVERNING_TECHNOLOGY [generate-id() = generate-id(key('gt', .)[@GTBookmark = $variable])]"> <xsl:sort select="." /> </xsl:apply-templates> For greater efficiency you could filter the GOVERNING_TECHNOLOGY elements that you check while creating the unique list as well: <xsl:apply-templates select="PRODUCT/GOVERNING_TECHNOLOGY[@GTBookmark = $variable] [generate-id() = generate-id(key('gt', .)[@GTBookmark = $variable])]"> <xsl:sort select="." /> </xsl:apply-templates> [Note that I'm here sorting by the value of the node rather than going through the rigamarole of getting the value of the first node returned by the key for its particular value, which will always be exactly the same thing, since the GOVERNING_TECHNOLOGY elements that you're sorting are always the first returned by the key.] The reason that filtering the GOVERNING_TECHNOLOGY elements that you're checking doesn't work on its own is that you're essentially checking, for each of those GOVERNING_TECHNOLOGY elements, whether they're the same as the first one returned by the key, but the key could return GOVERNING_TECHNOLOGY elements with different GTBookmark values, some of which might appear before the GOVERNING_TECHNOLOGYs that you're interested in, in which case there's no chance of them being the same node. You'll also have to filter the result of the key when you call the key to get the individual items of the group, otherwise you'll end up with all the GOVERNING_TECHNOLOGY elements with the same value, no matter what their GTBookmark is. I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ 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
|