This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RE: (Keys on multiple element types)


Hi Jen,

OK, so if I do

<xsl:key name="rows" match="FILES/*"
         use="concat(name(), '+', name)" />

<xsl:template match="FILES">
<xsl:apply-templates select="*[generate-id(.) =
    generate-id(key('rows', concat(name(), '+', name))[1])]"/>
</xsl:template>

<xsl:template match="FILES/*">
                   <xsl:value-of select="name"/>
                   <xsl:for-each select="key('rows', name)"> 
              	   <xsl:value-of select="$newline"/>
                   <xsl:value-of select="project_name"/>
                   <xsl:value-of select="$newline"/>
                </xsl:for-each>
</xsl:template>

I get FredFredHarry. So its removed the extra Fred but doesnt print the
project_names. If I change this so that instead of name I group by
project-name..thus

<xsl:key name="rows" match="FILES/*"
         use="concat(name(), '+', project_name)" />

<xsl:template match="FILES">
<xsl:apply-templates select="*[generate-id(.) =
    generate-id(key('rows', concat(name(), '+', project_name))[1])]"/>
</xsl:template>

<xsl:template match="FILES/*">
                   <xsl:value-of select="name"/>
                   <xsl:for-each select="key('rows', project_name)">
              	   <xsl:value-of select="$newline"/>
                   <xsl:value-of select="project_name"/>
                   <xsl:value-of select="$newline"/>
                </xsl:for-each>
</xsl:template>

I expect the output

Fred Building
Fred Looking
Harry Writing

but instead still get FredFredHarry. What am I doing/thinking wrong?

Ahmad

p.s many thanks for your gracious patience and  politeness.




At 11:55 AM 2/5/02 +0000, you wrote:
>Hi Ahmad,
>
>> You are correct in that I am trying to get to grips with keys, but I
>> didnt appreciate that they automatically removed duplicates based on
>> certain conditions, i.e if two say <project> nodes were the same.
>
>The keys don't; using the Muenchian method (which uses keys for
>efficiency) does. The duplicates are removed by the statement:
>
>  *[generate-id(.) = generate-id(key('rows', name)[1])]
>
>where you select all the elements that are the same element as the
>element you get when you use the 'rows' key with that element's name
>(i.e. selects the first element with a particular name in the
>document). The other elements with that name are still there.
>
>> Jeni's reply would be to use: -
>>
>> <xsl:key name="rows" match="FILES/*"
>>          use="concat(project(), '+', name)" />
>
>I suggested:
>
><xsl:key name="rows" match="FILES/*"
>         use="concat(name(), '+', name)" />
>
>Note that name() is an XPath function that retrieves the name of a
>node (in this case the name of the element that you're indexing with
>the key) - in your examples it would return things like 'RECORDA',
>'RECORDB' or 'RECORDC'. That means that the key values would be things
>like 'RECORDA+Fred' or 'RECORDC+Harry'. To get the unique values,
>you'd need:
>
>  *[generate-id(.) =
>    generate-id(key('rows', concat(name(), '+', name))[1])]
>
>You might find http://www.jenitennison.com/xslt/grouping helpful.
>
>Cheers,
>
>Jeni
>
>---
>Jeni Tennison
>http://www.jenitennison.com/
>
>
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
-------------------------------------------------
Ahmad J Reeves BSc (Hons) MSc (Dist) PhD Student
Information, Media & Communication Research Group
Department of Computer Science
Queen Mary, University of London
E1 4NS
Tel +44(0) 207 882 5257
Fax +44(0) 208 980 6533
http://www.dcs.qmw.ac.uk/imc

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]