Article
Problem
A Forum reader recently asked:
"I want like to query for an OU and retrieve several attributes. This is the script I am using:
<?xml version="1.0" encoding="UTF-8"?><policy
xmlns:query="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.XdsQueryProcessor">
<rule>
<description>GetData</description>
<conditions>
<and>
<if-class-name op="equal">User</if-class-name>
</and>
</conditions>
<actions>
<do-set-local-variable name="user-locID">
<arg-string>
<token-op-attr name="workforceID"/>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="result">
<arg-string>
<token-xpath expression='query:search($destQueryProcessor, "subtree",
"", "", "Organizational Unit", "OU", $user-locID, "L,Telephone
Number")/attr[@attr-name="L"]/value'/>
</arg-string>
</do-set-local-variable>
</actions>
</rule>
</policy>This works pretty well; after this script the result contains the value of "L", which I can set for a user account. Is it possible to retrieve not only L, but also Telephone Number? Of course I could do the same query with a new variable name, but this would result in several queries.
Is there an easy way to remove empty attributes from the XML doc? Or maybe there is a way not even to set an empty attribute."
And here's the response from Father Ramon ...
Solution
Place the raw result of the query into a variable of type node-set and then use that variable to get the results for individual values.
<do-set-local-variable name="result">
<arg-node-set>
<token-xpath expression='query:search($destQueryProcessor,
"subtree", "", "", "Organizational Unit", "OU", $user-locID,
"L,Telephone Number")'/>
</arg-node-set>
</do-set-local-variable>
<do-set-local-variable name="result-L">
<arg-string>
<token-xpath expression='$result/attr[@attr-name="L"]/value'/>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="result-phone">
<arg-string>
<token-xpath expression='$result/attr[@attr-name="Telephone
Number"]/value'/>
</arg-string>
</do-set-local-variable>Different attributes have different requirements as defined in the schema. String attributes can have a minimum and maximum length, and some attributes are defined to have a minimum attribute length of 1 and others of 0.
There are ways both to strip empty attributes and to not set them in the first place. The former would use strip-xpath with an expression like .//value[. = '']. The latter could be done in a couple of different ways. You could have separate rules that checked the values in the conditions and only set them if they were non-empty. Or, you could use a for-each as a psuedo-conditional - something like this:
<do-set-local-variable name="result">
<arg-node-set>
<token-xpath expression='query:search($destQueryProcessor, "subtree",
"", "", "Organizational Unit", "OU", $user-locID, "L,Telephone
Number")'/>
</arg-node-set>
</do-set-local-variable>
<do-for-each>
<arg-node-set>
<token-xpath expression='$result/attr[@attr-name="Telephone
Number"]/value'/>
</arg-node-set>
<arg-actions>
<do-add-dest-attr-value name="Telephone Number">
<arg-value>
<token-local-variable name="current-node"/>
</arg-value>
</do-add-dest-attr-value>
</arg-actions>
</do-for-each>
<do-for-each>
<arg-node-set>
<token-xpath expression='$result/attr[@attr-name="L"]/value'/>
</arg-node-set>
<arg-actions>
<do-add-dest-attr-value name="L">
<arg-value>
<token-local-variable name="current-node"/>
</arg-value>
</do-add-dest-attr-value>
</arg-actions>
</do-for-each> 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.
Related Articles
User Comments
- Be the first to comment! To leave a comment you need to Login or Register
- 6639 reads


0