[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Help with recursion (was: my brain is hurting)


Subject: [xsl] Help with recursion (was: my brain is hurting)
From: Chris Picton <chrisp@xxxxxxxxxxxxx>
Date: Sat, 15 Jan 2005 12:04:32 +0200

Hi all

Sorry about the subject line - my brain was more off than hurting, and looking at the instance I gave, I wonder why I wrote that at all. I had only just joined the list, and so didn't see David's mail about meaningful subject lines (which I should have used anyway). Sorry

Let my try clear up my own confusion (as I was writing from home where I didn't have my instance in front of me)

I have two (or more) separate subtrees in the instance.
The first, <users>, defines users and group and the relationship between them, and looks like:


 <users>
   <user name="chris" parent="othergroup">
     ...
   </user>
   <user name="phil" parent="othergroup">
     ...
   </user>
   <group name="default" parent="">
     ...
   </group>
   <group name="othergroup" parent="default">
     ...
   </group>
 </users>

The ... are to refer to extra nodes regarding the user not important here (such as full name, password, etc)

Then there is the <settings> subtree (there could be more than on such subtree, with settings for a different aspect of the user). I cannot merge the settings subtrees with the users subtrees, though (ie, I cannot have the settings per user under the <user> node the the <users> subtree). Design decision out of my hands.

the <settings> subtree looks like (fixed from first mail, and have renamed some nodes for legibility)

 <modulesettings>
   <user name="chris">
     <module useparent="1" >
         ...empty...
     </module>
   </user>
   <user name="phil">
     <module useparent="0" >
         ...module settings...
     </module>
   </user>
   <group name="default">
     <module useparent="0" >
         ...module settings...
     </module>
   </group>
   <group name="othergroup">
     <module useparent="1" >
         ...empty...
     </module>
   </group>
 </settings>

the 'useparent' attribute specifies if that user or group should inherit its settings from its parent (1), or if it should specify its own (0). I am trying to get a list of users per group who should use the settings defined by that group.

I iterate over each group name, and run the transform with <param name='group'/>, passing in each group name in turn.

In the above case, user 'phil' is not inheriting setting from the parent, and as such wont appear in the list for any group.
User 'chris' is inheriting from group 'othergroup', which is in turn inheriting from group 'default'. So, the user list for group 'default' should contain the user 'chris'.
The user list list for group 'othergroup' should be empty, as it has no settings of its own.


Hope that makes more sense!

I know I should be using recursion here, but I can't get my mind around the xsl way of doing things.


Thanks


Chris




Geert Josten wrote:


Hi Chris,

Could you be more precise? I'm confused about the way you are using <usegroup> (which doesn't look like a valid element to me? And why should parameter value 'default' result only in 'chris'?

Cheers,
Geert

Chris Picton wrote:

Hi all

I have the following xml structure.  To paraphrase quickly, I have users
and groups, each user or group has a parent group defined - except for
group 'default', which is always top of the tree.  I have settings for
each user and group.  Each settings node can be specified as 'use
settings from parent group', or 'specify my own settings'.

<root>
  <settings>
    <user name="chris">
      <usegroup="1" />
    </user>
    <user name="phil">
      <usegroup="0" />
      ...
    </user>
    <group name="default">
      <usegroup="0" />
      ...
    </group>
    <group name="othergroup">
      <usegroup="1" />
    </group>

  </settings>
  <users>
    <user name="chris" parent="othergroup">
      ...
    </user>
    <user name="phil" parent="othergroup">
      ...
    </user>
    <group name="default" parent="">
      ...
    </group>
    <group name="othergroup" parent="default">
      ...
    </group>
  </users>
</root>



I am trying to write a transform which, when given a group name as a
parameter, will output a list of usernames which will use that group's
settings.

Example, if parameter 'group' == default,
it will output "chris" in the above example

However, my xsl skills are nowhere near good enough for this.

Does anyone have ideas for me?

Regards

Chris


Current Thread
Keywords