Part of patch for XALANJ-1774

Added getNodeIDForStylesheetNSLookup method which is used to get the unique
stylesheet node ID for this node or the nearest enclosing element node in the
syntax tree that has namespace declarations.  If there is no such node, the
value -1 is returned.

Reviewed by Christine Li (jycli () ca ! ibm ! com)

diff --git a/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java b/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java
index 13ca687..55a619c 100644
--- a/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java
+++ b/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java
@@ -75,6 +75,12 @@
     protected AttributeList _attributes = null;   // Attributes of this element
     private   Hashtable _prefixMapping = null; // Namespace declarations
 
+    public static final int UNKNOWN_STYLESHEET_NODE_ID = -1;
+
+    // Records whether this node or any descendant needs to know the
+    // in-scope namespaces at transform-time
+    private int _nodeIDForStylesheetNSLookup = UNKNOWN_STYLESHEET_NODE_ID;
+
     // Sentinel - used to denote unrecognised syntaxt tree nodes.
     static final SyntaxTreeNode Dummy = new AbsolutePathPattern(null);
 
@@ -741,6 +747,35 @@
     }
 
     /**
+     * Retrieve an ID to identify the namespaces in scope at this point in the
+     * stylesheet
+     * @return An <code>int</code> representing the node ID or <code>-1</code>
+     *         if no namespace declarations are in scope
+     */
+    protected final int getNodeIDForStylesheetNSLookup() {
+        if (_nodeIDForStylesheetNSLookup == UNKNOWN_STYLESHEET_NODE_ID) {
+            Hashtable prefixMapping = getPrefixMapping();
+            int parentNodeID =
+                    (_parent != null) ? _parent.getNodeIDForStylesheetNSLookup()
+                                      : UNKNOWN_STYLESHEET_NODE_ID; 
+
+            // If this node in the stylesheet has no namespace declarations of
+            // its own, use the ID of the nearest ancestor element that does 
+            // have namespace declarations.
+            if (prefixMapping == null) {
+                _nodeIDForStylesheetNSLookup = parentNodeID;
+            } else {
+                // Inform the XSLTC object that we'll need to know about this
+                // node's namespace declarations.
+                _nodeIDForStylesheetNSLookup =
+                    getXSLTC().registerStylesheetPrefixMappingForRuntime(
+                                       prefixMapping, parentNodeID);
+            }
+        }
+
+        return _nodeIDForStylesheetNSLookup;
+    }
+    /**
      * Returns true if this expression/instruction depends on the context. By 
      * default, every expression/instruction depends on the context unless it 
      * overrides this method. Currently used to determine if result trees are