You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Anna Afonchenko <an...@ubaccess.com> on 2002/12/23 11:16:40 UTC

Stylesheet in Cocoon

Hi all. I am trying to create a stylesheet using cocoon and then apply this stylesheet to some input. I need to declare a root element with different namespace declarations.
When I was using batch file instead of Cocoon, I just wrote it as a string, e.g.:
<xsl:text disable-output-escaping="yes">
    &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:saxon="http://icl.com/saxon" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    &gt;
</xsl:text>
Since I was writing it to a file, it was written out as an root element.

But when I try to use the same method from Cocoon, it doesn't work, because Cocoon writes this out as a string, and in this case the output document will not have a root element.
I tried to declare the root inside an element, like this:

<xsl:element name="xsl:stylesheet">
    <xsl:attribute name="version">1.0</xsl:attribute>
    <xsl:attribute name="xmlns:xsl">http://www.w3.org/1999/XSL/Transform</xsl:attribute>
    <xsl:attribute name="xmlns:saxon">http://icl.com/saxon</xsl:attribute>
    <xsl:attribute name="xmlns:rdf">http://www.w3.org/1999/02/22-rdf-syntax-ns#</xsl:attribute>
    <xsl:attribute name="extension-element-prefixes">saxon</xsl:attribute>
</xsl:element>

But what I get in the output is this:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" extension-element-prefixes="saxon">

i.e. xmlns:saxon and xmlns:rdf weren't written out.
And then, when I try to run the generated stylesheet on the html input, I get an error:
type fatal
message org.apache.cocoon.ProcessingException: Could not read resource file:/C:/Program Files/Apache Group/Tomcat 4.1/webapps/cocoon/ub/violations.html: javax.xml.transform.TransformerException: org.xml.sax.SAXException: Invalid processing instruction name (saxon:warning)

sender org.apache.cocoon.servlet.CocoonServlet
source Cocoon servlet

I guess this is because the above namespace declarations are missing, because if I apply the xsl that was generated outside the Cocoon (using batch file) - it works fine, and the only difference that I can see between these two files is that namespace declarations thing.
Maybe it's because something else, I don't know, I am not good in Cocoon yet.
So if somebody have some idea, what is wrong with my code, and what should I do, please tell me.
P.S. I searched the archives for the issue of "invalid processing instruction (saxon:warning)" and found one topic, but I didn't understood it and I even don't know if this relates to my problem.

Thank you very much for help.

Anna

Re: Stylesheet in Cocoon

Posted by Joerg Heinicke <jo...@gmx.de>.
Hello Anna,

namespace declarations are no attributes, even if they look so. And you 
can't create them in this way. You can't create the important namespace 
nodes, you can only copy them.

To read a much better explanation from Jeni Tennison have a look here: 
http://www.dpawson.co.uk/xsl/sect2/N5536.html#d4840e1162. Maybe this 
shows you also the better way to create the XSLT using namespace-alias.

In general the namespaces shell be handled by the processor.

Regards,

Joerg

Anna Afonchenko wrote:
> Hi all. I am trying to create a stylesheet using cocoon and then apply 
> this stylesheet to some input. I need to declare a root element with 
> different namespace declarations.
> When I was using batch file instead of Cocoon, I just wrote it as a 
> string, e.g.:
> <xsl:text disable-output-escaping="yes">
>     &lt;xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>     
> xmlns:saxon="http://icl.com/saxon" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>     &gt;
> </xsl:text>
> Since I was writing it to a file, it was written out as an root element.
>  
> But when I try to use the same method from Cocoon, it doesn't work, 
> because Cocoon writes this out as a string, and in this case the output 
> document will not have a root element.
> I tried to declare the root inside an element, like this:
>  
> <xsl:element name="xsl:stylesheet">
>     <xsl:attribute name="version">1.0</xsl:attribute>
>     <xsl:attribute 
> name="xmlns:xsl">http://www.w3.org/1999/XSL/Transform</xsl:attribute>
>     <xsl:attribute name="xmlns:saxon">http://icl.com/saxon</xsl:attribute>
>     <xsl:attribute 
> name="xmlns:rdf">http://www.w3.org/1999/02/22-rdf-syntax-ns#</xsl:attribute>
>     <xsl:attribute name="extension-element-prefixes">saxon</xsl:attribute>
> </xsl:element>
>  
> But what I get in the output is this:
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
> extension-element-prefixes="saxon">
>  
> i.e. xmlns:saxon and xmlns:rdf weren't written out.
> And then, when I try to run the generated stylesheet on the html input, 
> I get an error:
> type fatal
> message _org.apache.cocoon.ProcessingException: Could not read resource 
> file:/C:/Program Files/Apache Group/Tomcat 
> 4.1/webapps/cocoon/ub/violations.html: 
> javax.xml.transform.TransformerException: org.xml.sax.SAXException: 
> Invalid processing instruction name (saxon:warning)_
> __ 
> sender org.apache.cocoon.servlet.CocoonServlet
> source Cocoon servlet
>  
> I guess this is because the above namespace declarations are missing, 
> because if I apply the xsl that was generated outside the Cocoon (using 
> batch file) - it works fine, and the only difference that I can see 
> between these two files is that namespace declarations thing.
> Maybe it's because something else, I don't know, I am not good in Cocoon 
> yet.
> So if somebody have some idea, what is wrong with my code, and what 
> should I do, please tell me.
> P.S. I searched the archives for the issue of "invalid processing 
> instruction (saxon:warning)" and found one topic, but I didn't 
> understood it and I even don't know if this relates to my problem.
>  
> Thank you very much for help.
>  
> Anna


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>