This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: sort | uniq via keys


Hi Saverio,

At 03:30 PM 2/14/02, you wrote:
>I am curious then as to the difference b/t the descendant, following,
>and following-sibling axes.

This is something that a good book can help with: no need for me to explain 
here. Or consult the XPath Recommendation: it's quite clear. (Find it at 
w3.org.)

>In addition, consider the following problem.  Instead of sorting and 
>uniqing the
>element names of `all' nodes in the input tree, I'd like to extract
>the names of elements residing at the same `level' in the input tree, 
>assuming a
>balanced input tree.

There are (at least) two ways to approach this. One would be to declare 
different keys for different levels, such as

<xsl:key name="features1" match="/*/*" use="name()"/>

which would only get you back elements directly under the document element 
(in your case, a and b elements) since those are the only ones it matches.

Another way is by ordering the way you traverse the tree, and using keys as 
you are now doing only to control the uniqueness.

(Of course, it's still going to test uniqueness relative to the entire 
document, not just to the level you're on; if you want the latter, you have 
to use different keys as above.)

The much maligned and abused <xsl:for-each> can be applied to this. From 
the root, for-each select="*" will get you only one level deep, 
select="*/*" will get you only two levels deep, and so on. (In these 
XPaths, the child:: axis is implicit, so e.g. */* is short for 
child::*/child::*, that is grandchildren.)

Again, the secret is in XPath. Check out the spec: it's not that hard.

Good luck,
Wendell


======================================================================
Wendell Piez                            mailto:wapiez@mulberrytech.com
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
======================================================================


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]