sboag 00/07/21 08:00:17
Modified: src/org/apache/xalan/xpath SimpleNodeLocator.java
Log:
Added patch by Gary Peskin <[EMAIL PROTECTED]>, to fix problem with unions,
Re: Docbook XSL w/ Xalan 1.1 : "XSLProcessorException unknown axis: 29".
Revision Changes Path
1.26 +16 -132
xml-xalan/src/org/apache/xalan/xpath/SimpleNodeLocator.java
Index: SimpleNodeLocator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/src/org/apache/xalan/xpath/SimpleNodeLocator.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- SimpleNodeLocator.java 2000/07/21 14:49:19 1.25
+++ SimpleNodeLocator.java 2000/07/21 15:00:16 1.26
@@ -60,8 +60,7 @@
import java.io.*;
import org.w3c.dom.*;
import org.apache.xalan.xpath.res.XPATHErrorResources;
-import org.apache.xalan.xpath.xml.ProblemListenerDefault;
-import org.apache.xalan.xpath.xml.PrefixResolverDefault;
+import org.apache.xalan.xpath.xml.ProblemListenerDefault;
/**
* <meta name="usage" content="advanced"/>
@@ -233,11 +232,12 @@
throws org.xml.sax.SAXException
{
XNodeSet resultNodeSet = null;
-
+ int endOfUnion = xpath.getNextOpPos(opPos);
opPos = xpath.getFirstChildPos(opPos);
// while((xpath.m_opMap[opPos] & XPath.LOCATIONPATHEX_MASK) ==
XPath.OP_LOCATIONPATH)
- while(xpath.m_opMap[opPos] > 0)
+ // while(xpath.m_opMap[opPos] > 0)
+ while(opPos < endOfUnion)
{
int nextOpPos = xpath.getNextOpPos(opPos);
@@ -675,126 +675,8 @@
}
}
return subQueryResults;
- }
-
- /**
- * Tricky implementation to realize returning correct namespace nodes.
- * // PATCH {blocks} PR:DMAN4KPPSQ Submitted by:<[EMAIL PROTECTED]>
namespace::* axis fix
- */
- private static class AttrProxy implements Attr {
- String m_name;
- String m_value;
- Element owner;
-
- AttrProxy(Node owner, Document factory, String name, String value) {
- // int colonpos = name.indexOf(':');
- // m_name = (colonpos < 0) ? "" : name.substring(colonpos+1);
- m_name = name;
- m_value = value;
- this.owner = (Element)owner;
- }
-
- AttrProxy(AttrProxy copyFrom) {
- m_name = copyFrom.m_name;
- m_value = copyFrom.m_value;
- owner = copyFrom.owner;
- }
-
- public Element getOwnerElement() {
- return this.owner;
- }
-
- public String getName() { return m_name; }
- public boolean getSpecified() { return false; }
- public String getValue() { return m_value; }
- public void setValue(String value) { m_name = value; }
-
- public Node appendChild(Node newChild)
- {
- /* never happens... should assert. */
- return null;
- }
- public Node cloneNode(boolean deep)
- {
- return new AttrProxy(this);
- }
-
- public NamedNodeMap getAttributes() { return null; /* a problem */ }
- public NodeList getChildNodes() { return null; /* never happens */ }
- public Node getFirstChild() { return null; }
- public Node getLastChild() { return null; }
- public String getLocalName()
- {
- return m_name;
- }
- public String getNamespaceURI()
- {
- return null; // ??
- }
- public Node getNextSibling()
- {
- return null; // ??
- }
- public String getNodeName() { return m_name; }
-
- public short getNodeType() { return Node.ATTRIBUTE_NODE; }
- public String getNodeValue() { return m_value; }
- public Document getOwnerDocument()
- { return this.owner.getOwnerDocument(); }
- public Node getParentNode() { return null; }
- public String getPrefix() { return "xmlns"; /* I guess */ }
- public Node getPreviousSibling() { return null; }
- public boolean hasChildNodes() { return false; }
- public Node insertBefore(Node newChild, Node refChild) {
- return null; /* never happens */ }
- public void normalize() { /* never happens -- can't mutate */ }
- public Node removeChild(Node oldChild) { return null; }
- public Node replaceChild(Node newChild, Node oldChild)
- {
- return null;
- }
- public void setNodeValue(String nodeValue) { /* never happens -- can't
mutate */ }
- public void setPrefix(String prefix) { /* never happens -- can't mutate
*/ }
- public boolean supports(String feature, String version) {
- return false; /* don't support anything... :-) */ }
- }
-
- private static final String S_XMLNAMESPACEURI =
PrefixResolverDefault.S_XMLNAMESPACEURI;
- /**
- * Collects all namespace nodes that are effective in the
<var>startNode<var>.
- * // PATCH {blocks} PR:DMAN4KPPSQ Submitted by:<[EMAIL PROTECTED]>
namespace::* axis fix
- * @param startNode A target element.
- * @return A hashtable; A key in the result is an attribute names such as
"xmlns", "xmlns:foo".
- * An element in the result is an <code>Attr</code> instance.
- */
- public static Hashtable collectNamespaceNodesInAncestors(Node startNode) {
- Node node = startNode;
- Hashtable nsnodes = new Hashtable();
- Document factory = startNode.getOwnerDocument(); // Null-check is not
needed.
- nsnodes.put("xmlns:xml", new AttrProxy(startNode, factory, "xmlns:xml",
S_XMLNAMESPACEURI));
- do {
- NamedNodeMap attributeList = node.getAttributes();
- if (attributeList != null) {
- int nAttrs = attributeList.getLength();
- for (int j = 0; j < nAttrs; j++) {
- Attr attr = (Attr)attributeList.item(j);
- String attrName = attr.getNodeName();
- if (attrName.equals("xmlns") || attrName.startsWith("xmlns:")) {
- if (!nsnodes.containsKey(attrName)) {
- if (node == startNode) {
- nsnodes.put(attrName, attr);
- } else {
- Attr newAttr = new AttrProxy(startNode, factory, attrName,
attr.getNodeValue());
- nsnodes.put(attrName, newAttr);
- }
- }
- }
- }
- }
- } while ((node = node.getParentNode()) != null);
- return nsnodes;
}
-
+
/**
* Add the namespace node of the context.
* @param xpath The xpath that is executing.
@@ -815,16 +697,18 @@
opPos = xpath.getFirstChildPosOfStep(opPos);
if( (null != context) && (context.getNodeType()==Node.ELEMENT_NODE) )
{
- // PATCH {blocks} PR:DMAN4KPPSQ Submitted by:<[EMAIL PROTECTED]>
namespace::* axis fix
- Hashtable nsnodes = collectNamespaceNodesInAncestors(context);
- Enumeration enum = nsnodes.keys();
- while (enum.hasMoreElements()) {
- String attrName = (String)enum.nextElement();
- Attr attr = (Attr)nsnodes.get(attrName);
- if(XPath.MATCH_SCORE_NONE != nodeTest(xpath, execContext, attr,
opPos, argLen, stepType))
+ NamedNodeMap attributeList = context.getAttributes();
+ if( attributeList != null )
+ {
+ int nAttrs = attributeList.getLength();
+ for( int j=0; j < nAttrs; j++ )
{
- subQueryResults = addNode(subQueryResults, attr);
- // If we have an attribute name here, we can quit.
+ Attr attr = (Attr)attributeList.item(j);
+ if(XPath.MATCH_SCORE_NONE != nodeTest(xpath, execContext, attr,
opPos, argLen, stepType))
+ {
+ subQueryResults = addNode(subQueryResults, attr);
+ // If we have an attribute name here, we can quit.
+ }
}
}
}