RE: [xsl] Selecting similar XML nodes by a sort criteria

Subject: RE: [xsl] Selecting similar XML nodes by a sort criteria
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 05 Oct 2007 16:06:37 -0400
Harsh,

At 12:36 PM 10/5/2007, you wrote:
Another question.

In your code, you have this line:

<xsl:template match="pile">
   <xsl:for-each
select="item[generate-id()=generate-id(key('item-by-number',@number)[1])
]">

What is the significance of [1] in the generate-id() function call?

As a positional predicate, it filters out all but the first (in document order) of the nodes selected in the node set it operates on.


Strictly speaking, in XSLT 1.0 you don't need it, since generate-id() will operate on the first node in the set in any case. But it avoids an error running under XSLT 2.0, so it's a good habit always to write it. Also, it's a tiny bit more legible to a reader who knows that the key will return several nodes, but not that generate-id() will operate only on the first (under XSLT 1.0).

Cheers,
Wendell


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

Current Thread