Re: [xsl] Using key with XPath and use value?

Subject: Re: [xsl] Using key with XPath and use value?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 15 Jan 2003 12:31:17 -0500
Steven,

You can enhance your key by including in its value some kind of identifier of the b element, to disambiguate d elements not only by their @pub, but by their b ancestors, as in:

<xsl:key name="pubsBySubheadandB" match="d"
   use="concat(generate-id(ancestor::b), '-', @pub)"/>

With this trick, you want to be careful, since the expression in @use now returns a string not a node-set. But since you never have more than one @pub per b element (attributes being what they are), you're okay here.

Naturally when you call the key you need to perform the same concatenation.

Cheers,
Wendell

At 12:14 PM 1/15/2003, you wrote:
If <xsl:key> is defined at the top-level of a document (i.e., globally), can
you get to values based on the XPath as well as the key value?

For example, I'm attempting to output subheads based on the attribute value
of an element. I have element <b> which can have several element <d>
descendants. <d> has a 'pub' attribute which is used to determine the
subhead I need and all matching pub attributes are grouped for output under
the appropriate subhead. <b>, however, can occur any number of times in a
document. If I define a key as such:

<xsl:key name="pubsBySubhead" match="d" use="@pub"/>

can I get to the values for only the specific <b> for which I'm processing?
I seem to be getting everything indexed in the key for each matching @pub,
which is basically all the matches thoughout the whole document.


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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



Current Thread