RE: [xsl] Ordering "roles"

Subject: RE: [xsl] Ordering "roles"
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 16 Aug 2006 17:05:13 +0100
The usual form of this problem is that the data forms a tree, then the
standard approach is to identify the root, apply-templates to it, and in
this template do an apply-templates on its logical children, found using an
expression such as:

select="//role[hasroles/include = current()/name]"

(though it's easier and more efficient to use keys).

If you need to look for cycles in the data, then it's a bit more difficult.

In your case it seems the data is not necessarily a tree, but an acyclic
graph. I think you can use essentially the same approach except that you
have to eliminate duplicates caused by reaching the same node by more than
one route. I'll have to delve into a dusty book on graph algorithms for that
one...

Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: Phillip B Oldham [mailto:phillip.oldham@xxxxxxxxxx] 
> Sent: 16 August 2006 16:07
> To: Mailing List: XSL
> Subject: [xsl] Ordering "roles"
> 
> Hi guys
> 
> I've got some xml in the following structure:
> 
> <roles>
>     <role>
>        <name>Create</name>
>        <hasroles />
>     </role>
>     <role>
>        <name>Approve</name>
>        <hasroles>
>           <include>Create</include>
>           <include>Edit</include>
>        </hasroles>
>     </role>
>     <role>
>        <name>Edit</name>
>        <hasroles>
>           <include>Create</include>
>        </hasroles>
>     </role>
> </roles>
> 
> So from this we can see that if your role is Edit, you can 
> also Create.
> 
> I need to produce an ordered list which takes into account 
> the above statement, such as:
> 
> <ul>
>     <li>Create</li>
>     <li>Edit</li>
>     <li>Approve</li>
> </ul>
> 
> Approve coming last in the list because it "includes" the 
> above two, Edit below that because it "includes" Create, and so on.
> 
> I'm using XSL1 with EXSLT.
> 
> Any ideas on how I can accomplish my goals?

Current Thread