Hi Simon,
I just searched the docs to see if it was possible to dynamically create a name attribute. Unfortunately, it's not.
http://cocoon.apache.org/1.x/xsp.html
The <xsp:attribute>
tag (which
requires a name
attribute)
is used in those cases where the attribute name is known at compile time, but
its attribute values are not.
Cheers,
Robby
-----Original Message-----
From: Simon Stanlake [mailto:[EMAIL PROTECTED]
Sent: dinsdag 7 maart 2006 20:24
To: users@cocoon.apache.org
Subject: RE: namespaces in root element of xsp generated pageMaybe this is what you were talking about, but it gave me an idea...<xsp:attribute name="xmlns:foo"><xsp:expr>this.contentHandler.startPrefixMapping(prefix,uri)</xsp:expr></xsp:attribute>won't work since startPrefixMapping returns null and addAttribute expects an object. however doing this (tested and it works)<xsp:pagelanguage="java"xmlns:xsp="http://apache.org/xsp"xmlns:xsp-request="http://apache.org/xsp/request/2.0"><xsp:structure><xsp:import>java.util.Date</xsp:import></xsp:structure><xsp:logic>String addNS(String prefix, String uri)throws SAXException{this.contentHandler.startPrefixMapping(prefix,uri);return new Date().toGMTString();}</xsp:logic><root><xsp:attribute name="createdOn"><xsp:expr>addNS(<xsp-request:get-parameter name="prefix"/>,<xsp-request:get-parameter name="uri"/>)</xsp:expr></xsp:attribute></root></xsp:page>results in<root createdOn="7 Mar 2006 19:15:04 GMT" xmlns:PREFIX="URI"/>which is what i wanted, with the side effect of having an extra attribute in the root element, which i can and will ignore :)Thanks for all your help - too bad I already made that transformer...
From: Pelssers, Robby, VF-NL [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 07, 2006 1:20 AM
To: users@cocoon.apache.org
Subject: RE: namespaces in root element of xsp generated pageI tested using the <xsp:attribute> for the root. It does work if you can get the namespace resolved in the xsp:Example that does work:<xsp:page
language="java"
xmlns:xsp="http://apache.org/xsp"><xsp:structure>
<xsp:include>java.util.*</xsp:include>
</xsp:structure>
<root>
<xsp:attribute name="ViewedOn"><xsp:expr>new Date().toGMTString()</xsp:expr></xsp:attribute>
<childtag>here comes the content</childtag>
</root>
</xsp:page>results in<root ViewedOn="7 Mar 2006 09:18:10 GMT">
<childtag>here comes the content</childtag>
</root>Cheers,Robby-----Original Message-----
From: Pelssers, Robby, VF-NL [mailto:[EMAIL PROTECTED]
Sent: dinsdag 7 maart 2006 9:56
To: users@cocoon.apache.org
Subject: RE: namespaces in root element of xsp generated pageIt will not work like<root><xsp:attribute name="xmlns:foo"><xsp:expr>this.contentHandler.startPrefixMapping(myprefix,myuri);</xsp:expr></xsp:attribute></root>but like<root><xsp:attribute name="xmlns:foo"><xsp:expr>this.contentHandler.startPrefixMapping(myprefix,myuri)</xsp:expr></xsp:attribute></root>You should leave out the ";" in the xsp:expr tag anyway :-)Cheers,Robby-----Original Message-----
From: Simon Stanlake [mailto:[EMAIL PROTECTED]
Sent: dinsdag 7 maart 2006 1:27
To: users@cocoon.apache.org
Subject: RE: namespaces in root element of xsp generated pageI don't think the attribute method will work, since when it goes through the pipeline it will not fire a startPrefixMapping() call.I ended up sticking a simple transformer in my pipeline that would add in the namespace declaration to the root element. However it would make sense to me to have something in the xsp processor like<xsp:namespace-decl prefix="foo" uri="http://www.foo.com"/>that would add in the namespace declarations to the root for you.anyways, thanks all for your help.r - simon
From: Pelssers, Robby, VF-NL [mailto:[EMAIL PROTECTED]
Sent: Monday, March 06, 2006 12:32 AM
To: users@cocoon.apache.org
Subject: RE: namespaces in root element of xsp generated page<root><xsp:attribute name="xmlns:foo"><xsp:expr>this.contentHandler.startPrefixMapping(myprefix,myuri);</xsp:expr></xsp:attribute></root>I don't know for sure if you can use xsp:attribute on the root tag...I guess so. But for this to work, the attribute name has to be fixed and the attribute value can be set dynamically.Cheers,Robby-----Original Message-----
From: Simon Stanlake [mailto:[EMAIL PROTECTED]
Sent: zaterdag 4 maart 2006 1:04
To: users@cocoon.apache.org
Subject: namespaces in root element of xsp generated pageHi,I've got an xsp page that I would like to have generate xml that looks like the following...<root xmlns:foo="http://www.foo.com"><data>hello</data></root>Problem is i'd like to have the foo namespace be dynamic, ie: come from a form variable or database or something. I can add dynamic namespace declarations inside the body of the xml document by going<root><xsp:logic>this.contentHandler.startPrefixMapping(myprefix,myuri);</xsp:logic><data>hello</data></root>which will add a declaration inside the <data/> element, but any content inside <xsp:logic/> tags that is outside the first non-xsp element will not be executed inside the generate() function, so this technique does not work with the root element.Is there a way to add a dynamic namespace declaration to the root element of an xsp-generated xml document? I've thought of intercepting the contentHandler and replacing with my own that does a startPrefixMapping() inside the body of startDocument, but I'm looking for something easier first.thanks in advance,Simon