[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Question about using Xpath in Dimitre xsl for LOOK

Subject: 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)
abbr. preceding a date
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:

<xref>
 <file1>
	<abbr>col1</abbr><name>label1</name>
	<abbr>col2</abbr><name>label2</name>
	<abbr>col3</abbr><name>label3</name>
	<abbr>col4</abbr><name>label4</name>
	<abbr>col5</abbr><name>label5</name>
 </file1>
 <file2>
	<abbr>col1</abbr><name>header1</name>
	<abbr>col2</abbr><name>header2</name>
 </file2>
</xref>

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 

preceding-sibling::abbr[1]

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,...
etc.
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
directly.


Cheers,
Dimitre Novatchev.


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.