RE: [xsl] Ordering nodes by number of children

Subject: RE: [xsl] Ordering nodes by number of children
From: "Andreas L. Delmelle" <a_l.delmelle@xxxxxxxxxx>
Date: Sun, 22 Feb 2004 15:41:32 +0100
> -----Original Message-----
> From: Smilen Dimitrov
> and suppose it was to be shown grafically on a tree display, in
> the same fashion as Windows Explorer shows them (folder icon and
> + expanding sign if the node has children, file icon and no sign
> if it has no children), and suppose that the engine that does the
> graphical display goes node by node in the hierarchy of the
> original xml. The problem is that for a long list, "files"
> (meaning a node without children) and "folders" (meaning a node
> with children) are scattered all over the place, and it don't
> look nice, basically... :) I was looking for a xsl script that
> would arrange the original xml in the same fashion that Windows
> explorer displays lists, that is, folders first, files later, for
> every level - that is, I was looking for the following output
> from the original xml:

See the other response for my proposed solution. Just adding a bit of
comments here:

If you start from a tree, in whatever order, that's always a dream when
you're working with XSL. You can use its capabilities WRT dealing with
hierarchies up to the fullest.

> Well, the solution that worked for me is below, and here is a
> short : First, template match="/node" instead of the root
> template match="/" since I do not want to access the document
> root, only my root node, which (should be) the only "node" child
> of the document root, so effectively it should be ran only once
> ?? (I hope :) )

Hmm. Yes, but then again, *every* XML document has only one root node, so
the root template is always called only once. The root template will match
the document root, whatever it's called (root, document, ...). If there is
at least one node called 'node', the apply-templates instruction without
select, in combination with the template matching 'node' nodes will trigger
the recursive tree-walk, as every apply-templates pushes the descendant
'node' nodes in the correct order through the template.

 XSL-List info and archive:

Current Thread