cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robin Green" <gree...@hotmail.com>
Subject [PATCH] and fix Re: Trouble with namespace
Date Wed, 16 Aug 2000 11:58:21 GMT
Alexander Krasilnikov <west@neonweb.ru> wrote:
>       I have strange trouble with namespace's. Small example:

I had a similar problem. The undocumented workaround is to replace

<em:page xmlns:em="http://west/">

with

<em:page xsp:em="http://west/">

The xsp: namespace prefix acts as a surrogate xmlns: and is read in and 
corrected by the XSP processor. The need for this is due to a frankly 
patronising flaw in the XSLT specification, where they decided that 
stylesheet authors should not be able to access xmlns attributes - I don't 
know why - presumably because there was "too much potential for 
confusion/abuse". Sigh.

Since the XSP processor uses a logicsheet (xsp-java.xsl) to do most of the 
xsp transformations, it is hampered by this limitation. However, I have a 
(not-very-much-tested) patch here which should allow you to use xmlns: in 
content elements (i.e. anything except the xsp:page element, which is 
reserved for logicsheet namespaces), in the standard way, and the 
substitition would be performed automatically.

This patch is primarily for the attention of the cocoon committers (if there 
are any not on vacation! :), so you can ignore it and just use the 
workaround if you wish.


--- 
/dannii/usr/local/cocoon/src/org/apache/cocoon/processor/xsp/language/java/XSPJavaPreprocessor.java

   Mon Jun 19 11:51:40 2000
+++ 
/dannii/home/users/greenrd/xml-cocoon/src/org/apache/cocoon/processor/xsp/language/java/XSPJavaPreprocessor.java

      Wed Aug 16 11:56:14 2000
@@ -60,7 +60,8 @@

/**
  * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
- * @version $Revision: 1.5 $ $Date: 2000/03/22 17:44:53 $
+ * @author <a href="mailto:greenrd@hotmail.com">Robin Green</a>
+ * @version $Revision: 1.6 $ $Date: 2000/08/16 11:53:53 $
  */
public class XSPJavaPreprocessor implements XSPPreprocessor {
   protected static XSPJavaProcessor javaProcessor = new XSPJavaProcessor();
@@ -112,8 +113,34 @@
         parent.replaceChild(textElement, node);

         break;
+
+      case Node.ATTRIBUTE_NODE:
+        // Hack to be able to copy over xmlns declaractions
+        // which cannot be matched by any XSLT pattern
+        Attr attr = (Attr) node;
+        String attName = attr.getName ();
+        if (attName.startsWith ("xmlns:")) {
+          // Replace with xsp:... which will be picked up
+          // by the xsp-java.xsl logicsheet
+          Element ownerE = attr.getOwnerElement ();
+          ownerE.setAttribute
+            ("xsp:" + attName.substring (6), attr.getValue ());
+          ownerE.removeAttribute (attName);
+        }
+        break;
+
       case Node.ELEMENT_NODE:
         ((Element) node).normalize();
+
+        if (!node.getNodeName ().equals ("xsp:page")) {
+          NamedNodeMap map = node.getAttributes ();
+          int attCount = map.getLength ();
+          for (int j = 0; j < attCount; j++) {
+            Node n = map.item(j);
+            if (n != null) this.process(n);
+          }
+        }                                                               +
         // Fall through
       default:
         NodeList childList = node.getChildNodes();



--
Robin Green
i-tao Ltd.
4 Skyline Village
Limeharbour
London E14 9TS
United Kingdom
Phone +44 20 7537 2233  Fax +44 70 8081 5118
http://www.i-tao.com


________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com


Mime
View raw message