I have a nodeset containing a number of nodes. For each node (an
instance) I'm trying to pull out an attribute value (in an ECMAScript
function). As far as I can tell, my code is correct and my XPath
expression is correct however my results are inconsistent.

OS: SLES 10 SP2 x86_64/OES 2 SP1
eDirectory: 8.8.6
IDM: 3.6.1
Designer: 3.0.1

Background information: I run queries against one or more staff IDs to
pull out contract objects associated with those staff IDs. I pass these
contracts into an ECMAScript function to do some processing of these
contracts (based on their start and end dates).

In the following example, I have three contract objects belonging to
one staff ID (17135) and two belonging to a second staff ID (17136)
retrieved through two separate queries and placed into the same nodeset
(local variable RLObject). If I use an XPath expression to pull out the
contract number from each object in turn, within the policy, it prints
out the correct value. I then pass the nodeset into an ECMAScript
function which, before it does anything else (purely for debugging
purposes), loops through each node in the nodeset and prints out the
contents of that node (using a home-grown function) and then prints out
the contract number and start and end dates of the same node using
DOMQuery.query and an XPath expression. The home-grown function prints
out the correct information, however the XPath queries give the correct
results only for the first contract of every staff ID - the following
contracts give the same results as the first query of a node with the
same staff ID.

If the same results were given for every contract then I could possibly
blame this on some sort of caching, however the correct results are
given every time the staff ID changes. I don't see why the staff ID
should be special and trigger the correct information to be printed. The
point at which the results change does correlate with the individual
queries that were made in order to build the nodeset, however my
printout of the node seems to imply that the current node contains the
correct information in each case.

I think I've explained all I can verbally. If anyone can point out
where I've gone wrong or make any suggestions I would be very grateful.
I'll now post the relevant snippets of policy, code and output - the
problem should be self-evident...


Policy Code
-----------------------------------------------------------------
<do-for-each>
<arg-node-set>
<token-xpath expression='$IdentityObj//attr[@attr-name="IDM
StaffID"]/value'/>
</arg-node-set>
<arg-actions>
<do-set-local-variable name="RLObjects" scope="policy">
<arg-node-set>
<token-local-variable name="RLObjects"/>
<token-query class-name="IDM RL Contract" datastore="src"
scope="subordinates">
<arg-dn>
<token-text
xml:space="preserve">Vault\Sources\ResourceLink\</token-text>
<token-local-variable name="current-node"/>
</arg-dn>
<arg-string>
<token-text xml:space="preserve">IDM RL StaffID</token-text>
</arg-string>
<arg-string>
<token-text xml:space="preserve">IDM RL Contract
No</token-text>
</arg-string>
<arg-string>
<token-text xml:space="preserve">IDM RL Contract
Start</token-text>
</arg-string>
<arg-string>
<token-text xml:space="preserve">IDM RL Contract
End</token-text>
</arg-string>
</token-query>
</arg-node-set>
</do-set-local-variable>
</arg-actions>
</do-for-each>
<do-for-each>
<arg-node-set>
<token-local-variable name="RLObjects"/>
</arg-node-set>
<arg-actions>
<do-trace-message>
<arg-string>
<token-xpath expression="$current-node/attr[@attr-name='IDM RL
Contract No']/value"/>
</arg-string>
</do-trace-message>
</arg-actions>
</do-for-each>
<do-set-local-variable name="AccStatusResult" scope="policy">
<arg-node-set>
<token-xpath expression="esrocessContracts($RLObjects)"/>
</arg-node-set>
</do-set-local-variable>


ECMAScript Code
-----------------------------------------------------------------
function processContracts(input) {
input.remove(input.first()); // Throw away the first entry - the first
time through the
// do-for-each loop in the policy it prepends an empty node
// to the node-set.

java.lang.System.out.println("Nodeset:");
myPrintNodeset(input);

...
}

function myPrintNode2(node, indent) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
java.lang.System.out.print(indent + "<" + node.getNodeName());
if (node.hasAttributes()) {
var attrs = node.getAttributes();
for (var count = 0; count < attrs.getLength(); count++) {
java.lang.System.out.print(" " + attrs.item(count).getNodeName() +
"='" + attrs.item(count).getNodeValue() + "'");
}
}
if (node.hasChildNodes()) {
java.lang.System.out.println(">");
var children = node.getChildNodes();
for (var count = 0; count < children.getLength(); count++) {
myPrintNode2(children.item(count), indent + "..");
}
java.lang.System.out.println(indent + "</" + node.getNodeName() +
">");
} else {
java.lang.System.out.println("/>");
}
} else if (node.getNodeType() == Node.TEXT_NODE) {
java.lang.System.out.println(indent + node.getNodeValue());
} else {
java.lang.System.out.println(indent + "Unknown node type: " +
node.getNodeType());
}
}

function myPrintNodeset(nodes) {
for (var node = nodes.first(); node != null; node = nodes.next()) {
myPrintNode2(node, "");
java.lang.System.out.println(DOMQuery.query(node,
'//attr[@attr-name="IDM RL Contract No"]/value'));
java.lang.System.out.println(DOMQuery.query(node,
'//attr[@attr-name="IDM RL StaffID"]/value'));
java.lang.System.out.println(DOMQuery.query(node,
'//attr[@attr-name="IDM RL Contract Start"]/value'));
java.lang.System.out.println(DOMQuery.query(node,
'//attr[@attr-name="IDM RL Contract End"]/value'));

}
}


Output
-----------------------------------------------------------------
<attached due to excessive size>


+----------------------------------------------------------------------+
|Filename: dtrace_xpath_weirdness.log |
|Download: http://forums.novell.com/attachment....achmentid=3562 |
+----------------------------------------------------------------------+

--
ChrisReeves
------------------------------------------------------------------------
ChrisReeves's Profile: http://forums.novell.com/member.php?userid=34172
View this thread: http://forums.novell.com/showthread.php?t=390930