This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: sort | uniq via keys
- From: Saverio Perugini <sperugin at csgrad dot cs dot vt dot edu>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 14 Feb 2002 15:30:17 -0500 (EST)
- Subject: Re: [xsl] sort | uniq via keys
- Reply-to: xsl-list at lists dot mulberrytech dot com
On Thu, 14 Feb 2002, Wendell Piez wrote:
> Using the following:: axis on your for-each, you are selecting nodes from
> those following your context node, the '/db' you have matched on.
>
> But your db is your document element, and has no following nodes.
>
> Just select your descendants (select="descendant::*[...]) and it should work.
Thank you Wendell.
I am curious then as to the difference b/t the descendant, following,
and following-sibling axes.
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.
e.g.,
in the following data
<db>
<a>
<d>
<j>...</j>
<k>...</k>
</d>
<e>
<l>...</l>
<m>...</m>
</e>
</a>
<b>
<f>
<n>...</n>
<o>...</o>
</f>
<g>
<p>...</p>
<q>...</q>
</g>
</b>
<c>
<h>
<r>...</r>
<s>...</s>
</h>
<i>
<t>...</t>
<u>...</u>
</i>
</c>
</db>
I would like the following output,
first level
-----------
a b c
second level
------------
d e f g h i
third level
-----------
j k l m n o p q r s t u
The following is my initial solution.
<xsl:template match="/db" priority="0.7">
<xsl:apply-templates select="*[1]"/>
</xsl:template>
<xsl:template match="*">
<xsl:for-each select="following-sibling::*">
<xsl:sort select="name()"/>
<xsl:value-of value="name()" />
</xsl:for-each>
<xsl:apply-templates select="*[1]"/>
</xsl:template>
<xsl:template match="text()"/>
This runs down the left-most path of the tree and collects siblings.
The problem is that is works at the sibling level, while I am
interested in an `entire' level in the tree.
Thank You and Best Regards,
Saverio Perugini
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list