From: Wolfgang M. M. <wol...@us...> - 2004-08-07 16:28:12
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/xquery In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14978/src/org/exist/xquery Modified Files: NamespaceConstructor.java XQuery.java ElementConstructor.java Log Message: Namespace declarations in direct or computed element constructors were only copied to the output if they were referenced by a element or attribute qname following the declaration. This made it difficult to write - for example - an XSLT fragment that used the namespace in an xsl:template. Namespace declarations are now preserved. They are attached to the element node in which they were declared. Index: XQuery.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/XQuery.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** XQuery.java 23 Jun 2004 12:46:35 -0000 1.2 --- XQuery.java 7 Aug 2004 16:28:02 -0000 1.3 *************** *** 84,88 **** AST ast = parser.getAST(); ! // LOG.debug("Generated AST: " + ast.toStringTree()); PathExpr expr = new PathExpr(context); treeParser.xpath(ast, expr); --- 84,88 ---- AST ast = parser.getAST(); ! LOG.debug("Generated AST: " + ast.toStringTree()); PathExpr expr = new PathExpr(context); treeParser.xpath(ast, expr); Index: NamespaceConstructor.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/NamespaceConstructor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NamespaceConstructor.java 29 Jun 2004 14:23:24 -0000 1.1 --- NamespaceConstructor.java 7 Aug 2004 16:28:02 -0000 1.2 *************** *** 76,80 **** context.declareInScopeNamespace(prefix, value); int nodeNr = builder.namespaceNode(prefix, value); ! return ((DocumentImpl)builder.getDocument()).getNode(nodeNr); } --- 76,80 ---- context.declareInScopeNamespace(prefix, value); int nodeNr = builder.namespaceNode(prefix, value); ! return ((DocumentImpl)builder.getDocument()).getNamespaceNode(nodeNr); } Index: ElementConstructor.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/xquery/ElementConstructor.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ElementConstructor.java 27 Jun 2004 21:10:06 -0000 1.5 --- ElementConstructor.java 7 Aug 2004 16:28:02 -0000 1.6 *************** *** 43,46 **** --- 43,47 ---- private PathExpr content = null; private AttributeConstructor attributes[] = null; + private QName namespaceDecls[] = null; public ElementConstructor(XQueryContext context) { *************** *** 62,66 **** public void addAttribute(AttributeConstructor attr) { ! if(attributes == null) { attributes = new AttributeConstructor[1]; attributes[0] = attr; --- 63,69 ---- public void addAttribute(AttributeConstructor attr) { ! if(attr.isNamespaceDeclaration()) { ! addNamespaceDecl(QName.extractLocalName(attr.getQName()), attr.getLiteralValue()); ! } else if(attributes == null) { attributes = new AttributeConstructor[1]; attributes[0] = attr; *************** *** 73,76 **** --- 76,91 ---- } + public void addNamespaceDecl(String prefix, String uri) { + if(namespaceDecls == null) { + namespaceDecls = new QName[1]; + namespaceDecls[0] = new QName(prefix, uri, "xmlns"); + } else { + QName decls[] = new QName[namespaceDecls.length + 1]; + System.arraycopy(namespaceDecls, 0, decls, 0, namespaceDecls.length); + decls[namespaceDecls.length] = new QName(prefix, uri, "xmlns"); + namespaceDecls = decls; + } + } + /* (non-Javadoc) * @see org.exist.xquery.Expression#eval(org.exist.xquery.StaticContext, org.exist.dom.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item) *************** *** 82,85 **** --- 97,106 ---- context.pushNamespaceContext(); MemTreeBuilder builder = context.getDocumentBuilder(); + // declare namespaces + if(namespaceDecls != null) { + for(int i = 0; i < namespaceDecls.length; i++) { + context.declareInScopeNamespace(namespaceDecls[i].getLocalName(), namespaceDecls[i].getNamespaceURI()); + } + } // process attributes AttributesImpl attrs = new AttributesImpl(); *************** *** 105,114 **** context.proceed(this, builder); constructor = (AttributeConstructor)attributes[i]; ! if(!constructor.isNamespaceDeclaration()) { ! attrValues = constructor.eval(contextSequence, contextItem); ! attrQName = QName.parse(context, constructor.getQName()); ! attrs.addAttribute(attrQName.getNamespaceURI(), attrQName.getLocalName(), attrQName.toString(), "CDATA", attrValues.getStringValue()); - } } } --- 126,133 ---- context.proceed(this, builder); constructor = (AttributeConstructor)attributes[i]; ! attrValues = constructor.eval(contextSequence, contextItem); ! attrQName = QName.parse(context, constructor.getQName()); ! attrs.addAttribute(attrQName.getNamespaceURI(), attrQName.getLocalName(), attrQName.toString(), "CDATA", attrValues.getStringValue()); } } *************** *** 122,125 **** --- 141,149 ---- int nodeNr = builder.startElement(qn, attrs); + if(namespaceDecls != null) { + for(int i = 0; i < namespaceDecls.length; i++) { + builder.namespaceNode(namespaceDecls[i]); + } + } // process element contents if(content != null) { *************** *** 131,135 **** return node; } ! /* (non-Javadoc) * @see org.exist.xquery.Expression#pprint() --- 155,159 ---- return node; } ! /* (non-Javadoc) * @see org.exist.xquery.Expression#pprint() |