Subject: Re: distinct filtering From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Tue, 14 Nov 2000 10:49:37 +0000 |
Gareth, > I am trying to display the data in the <PROMPT> tag of each requirement, but > I need to somehow filter the data so that I only display each list sequence > once. In other words, I want to display This is an example of a grouping-ish problem: you want to group all the PROMPTs together by their listsequence. How you go about it really depends on the size of your groups, whether they're already sorted, and so on. The basic point is to get hold of the PROMPTs that occur first in their particular group: there are no preceding PROMPTs that also belong to it. If the listsequences are in order, then you can use: PROMPT[parent::REQUIREMENT/@listsequence != preceding::PROMPT[1]/parent::REQUIREMENT/@listsequence] In other words: the PROMPT elements for which it is the case that their parent REQUIREMENT's listsequence is not the same as the preceding PROMPT's parent REQUIREMENT's listsequence. If the list sequences are not sorted, then you can use: PROMPT[not(parent::REQUIREMENT/@listsequence = preceding::PROMPT/parent::REQUIREMENT/@listsequence)] In other words: the PROMPT elements for which it is *not* the case that their parent REQUIREMENT's listsequence is the same as a preceding PROMPT's parent REQUIREMENT's listsequence. If there are lots of PROMPTs, then rather than the above, it's more efficient (in speed if not in memory) to use the Muenchian Method whereby you declare a key to help you index into the list of PROMPTs according to their parent REQUIREMENT's listsequence: <xsl:key name="prompts-by-listsequence" match="PROMPT" use="parent::REQUIREMENT/@listsequence" /> You can then check whether a particular PROMPT is first of those returned by the key for a particular listsequence by comparing its (generated) unique id with the unique id of the first returned by the key: PROMPT[generate-id() = generate-id(key('prompts-by-listsequence', parent::REQUIREMENT/@listsequence)[1])] In other words: the PROMPT elements whose unique id is the same as the unique id for the first element returned by the 'prompts-by-listsequence' key with the key value equal to the PROMPT's parent REQUIREMENT's listsequence. You can find out more about the Muenchian method at http://www.jenitennison.com/xslt/grouping/muenchian.html Once you have the PROMPT elements that you require with one of the above XPaths, you can iterate over them using xsl:for-each or apply templates to them with xsl:apply-templates to get the output that you want. I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
distinct filtering, GarethS | Thread | RE: distinct filtering, Xu, Xiaocun |
Re: Structured metadata within XSLT, David Carlisle | Date | Re: Equivalent of a Global Counter, Jeni Tennison |
Month |