Article

bstumpp's picture
article
Reads:

4463

Score:
2.666665
2.7
3
 
Comments:

0

Finding the Largest Nodeset with an IDM Rule

Author Info

26 March 2008 - 7:05am
Submitted by: bstumpp

(View Disclaimer)

Problem

A Forum reader recently asked:

"I'm trying to parse a nodeset and return the largest value. It sounds simple, but I've discovered that the xpath max function doesn't appear to exist with Novell's implementation.

I have a nodeset such as 01,02,03,09,05 etc that I need to parse to find the largest value. I want to do this in policies, if possible, to keep it simple. Does anyone have any brilliant ideas on how to parse this nodeset and find the largest value?"

And here is the response from Bob Stumpp ...

Solution

Try a rule something like the one below. No XPATH is needed; basically, you set a local variable to "0", then do a "for each" of your node set. If the local variable is less than the current node, update the local variable to the current node value and continue. When you are finished, the local variable will have the highest value in the node set.

<rule>
<description>Finding Greatest Value</description>
<conditions>
  <and>
    <if-class-name mode="nocase" op="equal">User</if-class-name>
  </and>
</conditions>
<actions>
  <do-set-local-variable name="local.counter" scope="policy">
    <arg-string>
      <token-text xml:space="preserve">0</token-text>
    </arg-string>
  </do-set-local-variable>
  <do-for-each>
    <arg-node-set>
      <token-text xml:space="preserve">Enter Node Set Here</token-text>
    </arg-node-set>
  <arg-actions>
  <do-if>
    <arg-conditions>
      <and>
        <if-local-variable mode="numeric" name="local.counter"
op="lt">$current-node$</if-local-variable>
      </and>
    </arg-conditions>
    <arg-actions>
      <do-set-local-variable name="local.counter" scope="policy">
        <arg-string>
          <token-local-variable name="current-node"/>
        </arg-string>
      </do-set-local-variable>
    </arg-actions>
    <arg-actions/>
      </do-if>
    </arg-actions>
  </do-for-each>
</actions>
</rule>


Disclaimer: As with everything else at Cool Solutions, this content is definitely not supported by Novell (so don't even think of calling Support if you try something and it blows up).

It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.




User Comments

© 2013 Novell