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: <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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Question about using Xpath in, Yang | Thread | [xsl] Re:Re:Question about using Xp, Yang |
[xsl] Question about using Xpath in, Yang | Date | [xsl] Re:Re:Question about using Xp, Yang |
Month |