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 …
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 NetIQ Cool Solutions, this content is definitely not supported by NetIQ, so Customer Support will not be able to help you if it has any adverse effect on your environment. It just worked for at least one person, and perhaps it will be useful for you too. Be sure to test in a non-production environment.