[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] accessing attributes


Subject: Re: [xsl] accessing attributes
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 09 Sep 2008 18:19:04 -0400

Tom,

At 03:34 PM 9/9/2008, you wrote:
Wendell,
Thanks for the prompt, clear reply. Advice like that so helps with
learning.
I take your point about using a xsl:key. I had tried this
<xsl:key name="fields" match="/*/fmp:METADATA/fmp:FIELD" use="position()"/>

However I now understand that position() function won't work as I expected.

Can you give me some similar clues how to get around this?

As you've discovered, the job of position() isn't to determine a node's position in the source tree. It returns the position of a node within its processing context, what's called the "current node list", which is relative to the particular traversal in which a node is retrieved (which can be different). So it's not useful here, since a key declaration doesn't have any processing context as such.


The usual solution to this problem is to determine your position directly by examining the tree. So:

<xsl:key name="fields" match="/*/fmp:METADATA/fmp:FIELD" use="count(preceding-sibling::fmp:FIELD) + 1"/>

will allow you to retrieve the fourth fmp:FIELD element with the key value '4', the ninth with value '9', etc.

In other words, by its "position".

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
Keywords
xml