Knowledge Partner
Knowledge Partner
274 views

Funny question about Nodeset variables and looping...

Here is one I never considered till that slacker AB asked me a silly
question....

If I have a nodeset variable. I build it with a couple of DN's in it.

Then I loop over that variable. Inside the loop, can I add to taht
variable? and thus cause extra loops to occur over the values I added?
Labels (1)
0 Likes
11 Replies
Anonymous_User Absent Member.
Absent Member.

Re: Funny question about Nodeset variables and looping...

Geoffrey Carman <geoffreycarmanNOSPAM@NOSPAMgmail.com> wrote:
> Here is one I never considered till that slacker AB asked me a silly question....
>
> If I have a nodeset variable. I build it with a couple of DN's in it.
>
> Then I loop over that variable. Inside the loop, can I add to taht
> variable? and thus cause extra loops to occur over the values I added?


Not with do-for-each as far as I know, it makes sense for that function to
finalise its list of items before iterating over them. Would need to test
it though.

Pretty sure you could do something like this with the do-while style loop
as it's gets re-evaluated each iteration.

--
If you find this post helpful and are logged into the web interface, show
your appreciation and click on the star below...
0 Likes
Knowledge Partner
Knowledge Partner

Re: Funny question about Nodeset variables and looping...

On 1/21/2015 2:52 PM, Alex McHugh wrote:
> Geoffrey Carman <geoffreycarmanNOSPAM@NOSPAMgmail.com> wrote:
>> Here is one I never considered till that slacker AB asked me a silly question....
>>
>> If I have a nodeset variable. I build it with a couple of DN's in it.
>>
>> Then I loop over that variable. Inside the loop, can I add to taht
>> variable? and thus cause extra loops to occur over the values I added?

>
> Not with do-for-each as far as I know, it makes sense for that function to
> finalise its list of items before iterating over them. Would need to test
> it though.
>
> Pretty sure you could do something like this with the do-while style loop
> as it's gets re-evaluated each iteration.


Nope, simple test shows it fails.

<rule>
<description>Test looping</description>
<conditions>
<and/>
</conditions>
<actions>
<do-set-local-variable name="NODESET" scope="policy">
<arg-node-set>
<token-text xml:space="preserve">1</token-text>
<token-text xml:space="preserve">2</token-text>
<token-text xml:space="preserve">3</token-text>
</arg-node-set>
</do-set-local-variable>
<do-for-each>
<arg-node-set>
<token-local-variable name="NODESET"/>
</arg-node-set>
<arg-actions>
<do-trace-message>
<arg-string>
<token-local-variable name="current-node"/>
</arg-string>
</do-trace-message>
<do-set-local-variable name="NODESET" scope="policy">
<arg-node-set>
<token-local-variable name="NODESET"/>
<token-text xml:space="preserve">4</token-text>
</arg-node-set>
</do-set-local-variable>
</arg-actions>
</do-for-each>
</actions>
</rule>


0 Likes
Knowledge Partner
Knowledge Partner

Re: Funny question about Nodeset variables and looping...

On 1/21/2015 2:59 PM, Geoffrey Carman wrote:
> On 1/21/2015 2:52 PM, Alex McHugh wrote:
>> Geoffrey Carman <geoffreycarmanNOSPAM@NOSPAMgmail.com> wrote:
>>> Here is one I never considered till that slacker AB asked me a silly
>>> question....
>>>
>>> If I have a nodeset variable. I build it with a couple of DN's in it.
>>>
>>> Then I loop over that variable. Inside the loop, can I add to taht
>>> variable? and thus cause extra loops to occur over the values I added?

>>
>> Not with do-for-each as far as I know, it makes sense for that
>> function to
>> finalise its list of items before iterating over them. Would need to test
>> it though.
>>
>> Pretty sure you could do something like this with the do-while style loop
>> as it's gets re-evaluated each iteration.

>
> Nope, simple test shows it fails.
>
> <rule>
> <description>Test looping</description>
> <conditions>
> <and/>
> </conditions>
> <actions>
> <do-set-local-variable name="NODESET" scope="policy">
> <arg-node-set>
> <token-text xml:space="preserve">1</token-text>
> <token-text xml:space="preserve">2</token-text>
> <token-text xml:space="preserve">3</token-text>
> </arg-node-set>
> </do-set-local-variable>
> <do-for-each>
> <arg-node-set>
> <token-local-variable name="NODESET"/>
> </arg-node-set>
> <arg-actions>
> <do-trace-message>
> <arg-string>
> <token-local-variable name="current-node"/>
> </arg-string>
> </do-trace-message>
> <do-set-local-variable name="NODESET" scope="policy">
> <arg-node-set>
> <token-local-variable name="NODESET"/>
> <token-text xml:space="preserve">4</token-text>
> </arg-node-set>
> </do-set-local-variable>
> </arg-actions>
> </do-for-each>
> </actions>
> </rule>


And using Append XML tokens to try and add new nodes into the nodeset on
the fly does not work either. Take 2 rule.



<rule>
<description>Test looping</description>
<conditions>
<and/>
</conditions>
<actions>
<do-set-local-variable disabled="true" name="NODESET" scope="policy">
<arg-node-set>
<token-text xml:space="preserve">1</token-text>
<token-text xml:space="preserve">2</token-text>
<token-text xml:space="preserve">3</token-text>
</arg-node-set>
</do-set-local-variable>
<do-for-each disabled="true">
<arg-node-set>
<token-local-variable name="NODESET"/>
</arg-node-set>
<arg-actions>
<do-trace-message>
<arg-string>
<token-local-variable name="current-node"/>
</arg-string>
</do-trace-message>
<do-set-local-variable name="NODESET" scope="policy">
<arg-node-set>
<token-local-variable name="NODESET"/>
<token-xpath expression="$current-node + 1"/>
</arg-node-set>
</do-set-local-variable>
</arg-actions>
</do-for-each>
<do-set-local-variable name="NODESET" scope="policy">
<arg-node-set>
<token-xml-parse>
<token-text xml:space="preserve"><top>
<node>1</node>
<node>2</node>
<node>3</node>
</top></token-text>
</token-xml-parse>
</arg-node-set>
</do-set-local-variable>
<do-for-each>
<arg-node-set>
<token-xpath expression="$NODESET/top/*"/>
</arg-node-set>
<arg-actions>
<do-trace-message>
<arg-string>
<token-local-variable name="current-node"/>
</arg-string>
</do-trace-message>
<do-set-local-variable name="NEXT" scope="policy">
<arg-string>
<token-xpath expression="$current-node + 1"/>
</arg-string>
</do-set-local-variable>
<do-append-xml-element expression="$NODESET/top[last()]" name="node"/>
<do-append-xml-text expression="$NODESET/top/node[last()]">
<arg-string>
<token-local-variable name="NEXT"/>
</arg-string>
</do-append-xml-text>
</arg-actions>
</do-for-each>
<do-trace-message>
<arg-string>
<token-xml-serialize>
<token-local-variable name="NODESET"/>
</token-xml-serialize>
</arg-string>
</do-trace-message>
</actions>
</rule>

Oh well. Would have been fun. Oh, one more idea...


0 Likes
Knowledge Partner
Knowledge Partner

Re: Funny question about Nodeset variables and looping...

On 1/21/2015 3:13 PM, Geoffrey Carman wrote:
> On 1/21/2015 2:59 PM, Geoffrey Carman wrote:
>> On 1/21/2015 2:52 PM, Alex McHugh wrote:
>>> Geoffrey Carman <geoffreycarmanNOSPAM@NOSPAMgmail.com> wrote:
>>>> Here is one I never considered till that slacker AB asked me a silly
>>>> question....
>>>>
>>>> If I have a nodeset variable. I build it with a couple of DN's in it.
>>>>
>>>> Then I loop over that variable. Inside the loop, can I add to taht
>>>> variable? and thus cause extra loops to occur over the values I added?
>>>
>>> Not with do-for-each as far as I know, it makes sense for that
>>> function to
>>> finalise its list of items before iterating over them. Would need to
>>> test
>>> it though.
>>>
>>> Pretty sure you could do something like this with the do-while style
>>> loop
>>> as it's gets re-evaluated each iteration.

>>
>> Nope, simple test shows it fails.
>>
>> <rule>
>> <description>Test looping</description>
>> <conditions>
>> <and/>
>> </conditions>
>> <actions>
>> <do-set-local-variable name="NODESET" scope="policy">
>> <arg-node-set>
>> <token-text xml:space="preserve">1</token-text>
>> <token-text xml:space="preserve">2</token-text>
>> <token-text xml:space="preserve">3</token-text>
>> </arg-node-set>
>> </do-set-local-variable>
>> <do-for-each>
>> <arg-node-set>
>> <token-local-variable name="NODESET"/>
>> </arg-node-set>
>> <arg-actions>
>> <do-trace-message>
>> <arg-string>
>> <token-local-variable name="current-node"/>
>> </arg-string>
>> </do-trace-message>
>> <do-set-local-variable name="NODESET" scope="policy">
>> <arg-node-set>
>> <token-local-variable name="NODESET"/>
>> <token-text xml:space="preserve">4</token-text>
>> </arg-node-set>
>> </do-set-local-variable>
>> </arg-actions>
>> </do-for-each>
>> </actions>
>> </rule>

>
> And using Append XML tokens to try and add new nodes into the nodeset on
> the fly does not work either. Take 2 rule.
>
>
>
> <rule>
> <description>Test looping</description>
> <conditions>
> <and/>
> </conditions>
> <actions>
> <do-set-local-variable disabled="true" name="NODESET"
> scope="policy">
> <arg-node-set>
> <token-text xml:space="preserve">1</token-text>
> <token-text xml:space="preserve">2</token-text>
> <token-text xml:space="preserve">3</token-text>
> </arg-node-set>
> </do-set-local-variable>
> <do-for-each disabled="true">
> <arg-node-set>
> <token-local-variable name="NODESET"/>
> </arg-node-set>
> <arg-actions>
> <do-trace-message>
> <arg-string>
> <token-local-variable name="current-node"/>
> </arg-string>
> </do-trace-message>
> <do-set-local-variable name="NODESET" scope="policy">
> <arg-node-set>
> <token-local-variable name="NODESET"/>
> <token-xpath expression="$current-node + 1"/>
> </arg-node-set>
> </do-set-local-variable>
> </arg-actions>
> </do-for-each>
> <do-set-local-variable name="NODESET" scope="policy">
> <arg-node-set>
> <token-xml-parse>
> <token-text xml:space="preserve"><top>
> <node>1</node>
> <node>2</node>
> <node>3</node>
> </top></token-text>
> </token-xml-parse>
> </arg-node-set>
> </do-set-local-variable>
> <do-for-each>
> <arg-node-set>
> <token-xpath expression="$NODESET/top/*"/>
> </arg-node-set>
> <arg-actions>
> <do-trace-message>
> <arg-string>
> <token-local-variable name="current-node"/>
> </arg-string>
> </do-trace-message>
> <do-set-local-variable name="NEXT" scope="policy">
> <arg-string>
> <token-xpath expression="$current-node + 1"/>
> </arg-string>
> </do-set-local-variable>
> <do-append-xml-element
> expression="$NODESET/top[last()]" name="node"/>
> <do-append-xml-text
> expression="$NODESET/top/node[last()]">
> <arg-string>
> <token-local-variable name="NEXT"/>
> </arg-string>
> </do-append-xml-text>
> </arg-actions>
> </do-for-each>
> <do-trace-message>
> <arg-string>
> <token-xml-serialize>
> <token-local-variable name="NODESET"/>
> </token-xml-serialize>
> </arg-string>
> </do-trace-message>
> </actions>
> </rule>
>
> Oh well. Would have been fun. Oh, one more idea...


And clone by XPATH does not work either.

<rule>
<description>Test looping - use Clone by XPATH</description>
<conditions>
<and/>
</conditions>
<actions>
<do-set-local-variable name="NODESET" scope="policy">
<arg-node-set>
<token-xml-parse>
<token-text xml:space="preserve"><top>
<node>1</node>
<node>2</node>
<node>3</node>
</top></token-text>
</token-xml-parse>
</arg-node-set>
</do-set-local-variable>
<do-for-each>
<arg-node-set>
<token-xpath expression="$NODESET/top/*"/>
</arg-node-set>
<arg-actions>
<do-trace-message>
<arg-string>
<token-local-variable name="current-node"/>
</arg-string>
</do-trace-message>
<do-set-local-variable name="NEXT" scope="policy">
<arg-node-set>
<token-xml-parse>
<token-text xml:space="preserve"><node>next</node></token-text>
</token-xml-parse>
</arg-node-set>
</do-set-local-variable>
<do-clone-xpath dest-expression="$NODESET/top[last()]"
src-expression="$NEXT/*"/>
</arg-actions>
</do-for-each>
<do-trace-message>
<arg-string>
<token-xml-serialize>
<token-local-variable name="NODESET"/>
</token-xml-serialize>
</arg-string>
</do-trace-message>
</actions>
</rule>



0 Likes
Knowledge Partner
Knowledge Partner

Re: Funny question about Nodeset variables and looping...

On 1/21/2015 3:17 PM, Geoffrey Carman wrote:
> On 1/21/2015 3:13 PM, Geoffrey Carman wrote:
>> On 1/21/2015 2:59 PM, Geoffrey Carman wrote:
>>> On 1/21/2015 2:52 PM, Alex McHugh wrote:
>>>> Geoffrey Carman <geoffreycarmanNOSPAM@NOSPAMgmail.com> wrote:
>>>>> Here is one I never considered till that slacker AB asked me a silly
>>>>> question....
>>>>>
>>>>> If I have a nodeset variable. I build it with a couple of DN's in it.
>>>>>
>>>>> Then I loop over that variable. Inside the loop, can I add to taht
>>>>> variable? and thus cause extra loops to occur over the values I
>>>>> added?
>>>>
>>>> Not with do-for-each as far as I know, it makes sense for that
>>>> function to
>>>> finalise its list of items before iterating over them. Would need to
>>>> test
>>>> it though.
>>>>
>>>> Pretty sure you could do something like this with the do-while style
>>>> loop
>>>> as it's gets re-evaluated each iteration.


And there you go, here it works via a While loop.

<rule>
<description>Test looping - While loop, using Clone by XPATH</description>
<conditions>
<and/>
</conditions>
<actions>
<do-set-local-variable name="NODESET" scope="policy">
<arg-node-set>
<token-xml-parse>
<token-text xml:space="preserve"><top>
<node>1</node>
<node>2</node>
<node>3</node>
</top></token-text>
</token-xml-parse>
</arg-node-set>
</do-set-local-variable>
<do-set-local-variable name="COUNT" scope="policy">
<arg-string>
<token-text xml:space="preserve">1</token-text>
</arg-string>
</do-set-local-variable>
<do-while>
<arg-conditions>
<and>
<if-xpath op="true">$NODESET/top/node[position()=$COUNT]</if-xpath>
<if-local-variable mode="numeric" name="COUNT"
op="lt">6</if-local-variable>
</and>
</arg-conditions>
<arg-actions>
<do-trace-message>
<arg-string>
<token-xpath
expression="$NODESET/top/node[position()=$COUNT]/text()"/>
</arg-string>
</do-trace-message>
<do-set-local-variable name="NEXT" scope="policy">
<arg-node-set>
<token-xml-parse>
<token-text xml:space="preserve"><node>next</node></token-text>
</token-xml-parse>
</arg-node-set>
</do-set-local-variable>
<do-clone-xpath dest-expression="$NODESET/top[last()]"
src-expression="$NEXT/*"/>
<do-set-local-variable name="COUNT" scope="policy">
<arg-string>
<token-xpath expression="$COUNT + 1"/>
</arg-string>
</do-set-local-variable>
</arg-actions>
</do-while>
<do-trace-message>
<arg-string>
<token-xml-serialize>
<token-local-variable name="NODESET"/>
</token-xml-serialize>
</arg-string>
</do-trace-message>
</actions>
</rule>

0 Likes
Anonymous_User Absent Member.
Absent Member.

Re: Funny question about Nodeset variables and looping...

Geoffrey Carman wrote:

> > > > > > Pretty sure you could do something like this with the do-while style
> > > > > loop
> > > > > as it's gets re-evaluated each iteration.

>
> And there you go, here it works via a While loop.


Just like I said.

Now you can do some tricks with nodesets and do-for-each, but whatever you do - all the valid nodes that were identified at the top of the "do-for-each" are processed.
This is true even if you do-strip-xpath some or all unprocessed nodes within the do-for-each.
you don't need to explicitly refer back to the original $NODESET variable within the body of a do-for-each.
The parent nodes of $current-node can be accessed instead and will affect the original $NODESET variable.
For example $current-node/../*[last()] is the same as $NODESET/top/*[last()]

0 Likes
Anonymous_User Absent Member.
Absent Member.

Re: Funny question about Nodeset variables and looping...

Just to provide a bit more of the "business case", the idea is to
automatically create distribution lists of people working for a given
manager; that's easy enough, as it's just one loop, but what about for a
director, or VP, or other n-level person? Getting their direct reports
only is still easy, but handling the n-levels of subordinates is what led
to this. If using ECMAscript I would just build an array and iterate over
it over and over, but without having n-number of loops I could not figure
this out with just foreach. If I have n-number of loops, then this works,
but what about when the org grows and has n+1 levels? Bleh.

I'll give 'while' a shot and post back the solution.

--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...
0 Likes
Knowledge Partner
Knowledge Partner

Re: Funny question about Nodeset variables and looping...

On 1/21/2015 6:31 PM, ab wrote:
> Just to provide a bit more of the "business case", the idea is to
> automatically create distribution lists of people working for a given
> manager; that's easy enough, as it's just one loop, but what about for a
> director, or VP, or other n-level person? Getting their direct reports
> only is still easy, but handling the n-levels of subordinates is what led
> to this. If using ECMAscript I would just build an array and iterate over
> it over and over, but without having n-number of loops I could not figure
> this out with just foreach. If I have n-number of loops, then this works,
> but what about when the org grows and has n+1 levels? Bleh.
>
> I'll give 'while' a shot and post back the solution.


I sent you some samples, hope they help.

0 Likes
Anonymous_User Absent Member.
Absent Member.

Re: Funny question about Nodeset variables and looping...

On 1/21/2015 12:44 PM, Geoffrey Carman wrote:
> Here is one I never considered till that slacker AB asked me a silly question....
>
> If I have a nodeset variable. I build it with a couple of DN's in it.
>
> Then I loop over that variable. Inside the loop, can I add to taht variable? and thus cause extra loops to occur over the
> values I added?


One thing you could do is to clone the VARIABLE1 into VARIABLE1A
Then iterate on VARIABLE1 but make your changes to it's clone of VARIABLE 1A
So:
While something
Clone vars
For each the var
Clone the vars to reload
Do While

Then after the first loop through it will run again and reload from the while using the new set of values potentially.


--
-----------------------------------------------------------------------
Will Schneider
Knowledge Partner http://forums.netiq.com

If you find this post helpful, please click on the star below.
0 Likes
Knowledge Partner
Knowledge Partner

Re: Funny question about Nodeset variables and looping...

On 1/22/2015 3:38 PM, Will Schneider wrote:
> On 1/21/2015 12:44 PM, Geoffrey Carman wrote:
>> Here is one I never considered till that slacker AB asked me a silly
>> question....
>>
>> If I have a nodeset variable. I build it with a couple of DN's in it.
>>
>> Then I loop over that variable. Inside the loop, can I add to taht
>> variable? and thus cause extra loops to occur over the
>> values I added?

>
> One thing you could do is to clone the VARIABLE1 into VARIABLE1A
> Then iterate on VARIABLE1 but make your changes to it's clone of
> VARIABLE 1A
> So:
> While something
> Clone vars
> For each the var
> Clone the vars to reload
> Do While
>
> Then after the first loop through it will run again and reload from the
> while using the new set of values potentially.


No need to do that, I think, my WHILE approach (Which to be fair was
your suggestion when I asked you offline, and Alex's suggestion at the
outset. But I do not trust either of you critters as far as I can throw
you, and I throw like a girl. So not very far at all (Unless that girl
is Madonna or Rosie O'Donnell, what was that movie again?)).

See my While loop approach, seems to work on modifying it inside the loop.


0 Likes
Knowledge Partner
Knowledge Partner

Re: Funny question about Nodeset variables and looping...

Geoffrey Carman wrote:

> See my While loop approach, seems to work on modifying it inside the loop.


Yes, that's working nicely. Do it the other way round (removing processed nodes
from the nodest inside the while loop) in several places.
______________________________________________
https://www.is4it.de/identity-access-management
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.