Re: [xsl] Purpose of generate-id index [1]

Subject: Re: [xsl] Purpose of generate-id index [1]
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 24 Jun 2003 15:51:30 -0400
John,

Strictly speaking, in XSLT 1.0 the [1] predicate is not necessary on the construction:

generate-id(key('foo','bar'))[1])

since generate-id, when given a node set as an argument, returns a generated ID only for the first node in the set.

Generally, people are in the habit of including it only (I suppose) to clarify for the downstream maintainer that they're only going to get an ID for the first node in the set, in document order -- which as you point out is precisely what they'd get in any case. Or perhaps they just aren't sure, and take the safe bet. XPath, especially in cases like this, can be beautifully concise, but by the same token, terribly obscure.

I don't know the extent to which processors are smart enough to optimize this away, or whether they really do filter the node set to one member before giving it to the generate-id() function (which would filter it anyway).

Cheers,
Wendell

At 03:25 PM 6/24/2003, you wrote:
>Hello, I have been successfully using the generate-id() function
>with a key, without fully understanding the purpose of the [1]
>index construct.
>
>One explanation is given - "Given a node-set, generate-id
>returns an ID for the node in the node-set that occurs first
>in document order" (O'Reilly XSLT)
>
>e.g.
>/TDLfile[generate-id(.)=generate-id(
>          key('TimingByGroup',concat(@type,'::',@period))[1])]
>
>In general terms why is the [1] index present.


======================================================================
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