Re: [xsl] [solved] key with many uses's

Subject: Re: [xsl] [solved] key with many uses's
From: Elizabeth Barham <soggytrousers@xxxxxxxxx>
Date: 06 Feb 2002 15:56:33 -0600
Hi Elizabeth,

Elizabeth Barham <soggytrousers@xxxxxxxxx> writes:
> I have a series of elements that I would like to group based on more
> than one parameter.
> 
> 1. <phone>713-228-XXXX</phone>
> 2. <phone type="fax">713-228-XXXX</phone>
> 3. <phone type="special" description="clients" paren="1" description-place="before">713-228-XXXX</phone>
> 4. <phone type="special" description="AIDS legal hotline:" paren="0" description-place="before">713-528-XXXX</phone>
> 5. <phone type="special" description="AIDS legal hotline:" paren="0" description-place="before" >800-528-XXXX</phone>
> 
> In this example, I'd like to somehow get both 4 and 5 together. I've
> considered using three keys:
> 	
> <xsl:key name="special-phone-d" match="phone[@type='special']" use="@description"/>
> <xsl:key name="special-phone-p" match="phone[@type='special']" use="@paren"/>
> <xsl:key name="special-phone-w" match="phone[@type='special']" use="@description-place"/>
> 
> and one key:
> 
> <xsl:key name="special-phone" match="phone[@type='special']" use ="@description | @paren | @description-place" />

You're better of using the second method as the first is goofy,
cumbersome and not very pretty to boot.

> Using the Muenchian Method it'd be something like this using the three
> keys:
> 
> <xsl:for-each select="$nodes[generate-id(.)] = generate-id(key('special-phone-d', @description)[1])]
> 	and
> 	$nodes[generate-id(.)] = generate-id(key('special-phone-p', @paren)[1])
> 	and
> 	$nodes[generate-id(.)] = generate-id(key('special-phone-w', @description-place)[1])">
> 

Try this:

<xsl:for-each select="$nodes[generate-id(.) = generate-id(key('special-phones', string(@description, @paren, @description-place))[1])]">

Why does this work as opposed to

<xsl:for-each select="$nodes[generate-id(.) = generate-id(key('special-phones', @description | @paren | @description-place)[1])]">

I hear you ask? Good question. Perhaps with a little more experience I
shall be able to answer this one myself.

Elizabeth

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


Current Thread