[xsl] Re: Question about using Xpath in Dimitre xsl for LOOKup problem

Subject: [xsl] Re: Question about using Xpath in Dimitre xsl for LOOKup problem
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Sat, 23 Jun 2001 21:37:42 -0700 (PDT)
Yang wrote:

>  In your xsl solution to Benoit_Aumars lookup problem;(1048, 1004)
>  you use following key commands to get relation between name and abbr.
>   <xsl:key name="kLookup" match="name" use="preceding-sibling::abbr[1]"/>
>  It seems a very smart and compact expression, especially the xpath 
>  preceding-sibling:: abbr[1] for use attribute.
>  However I can not understand how exactly this xpath does the trick
>  with all my reading about preceding-sibling, predicate[1]?

Hi Sun-fu,

Let's remember how the lookup.xml file looks like:


We want to use it to translate a string that is equal to the text of one of the
"abbr" elements to the text of its immediately following "name" sibling.

The xsl:key definition:

  <xsl:key name="kLookup" match="name" use="preceding-sibling::abbr[1]"/>

allows to have the following:

key('kLookup', $someAbbr)

so that if a "name" element exists, and its immediate preceding "abbr" sibling has
the same string value as $someAbbr, then the above expression returns (any) "name"
element with this property.

What you probably don't understand is the use of a numerical index in 


This (as usual) means "Pick up the first node from the node-set".

The only special thing to note here is that the "preceding-sibling" is a reverse
axis, and this affects the meaning of position() -- positions are counted in reverse
document order.

Apart from this, the code is pretty short and self-explanatory. 

In case you might have any further questions -- you're welcome.

Certainly, other people might explain this in bigger detail, including what is the
reason for this solution, what was I thinking while writing it, why was I thinking
so, what are the shortcomings and the neat ideas, why I did it on a Saturday,...
Other people will start giving you advices for your private life...

In case you need such kind of help (which I doubt :) ) -- don't ask me but ask them

Dimitre Novatchev.

Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail

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

Current Thread