You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by roy huang <li...@hotmail.com> on 2004/02/27 10:51:26 UTC

[Help]writing SAX Transformer

I wrote a transformer extend AbstractSAXTransformer to transform woody form define file base on action and state.
The transformer do two thing:
1.turn <wd:field> to <wd:output> for read-only
2.delete some define widgets under certain condition.I use this.startRecording(); this.endRecording to delete the widget .
Question 1:
It looks fine when I use browser to see the xml output.But if I check the source ,I found if the original xml is like:
<?xml version="1.0" encoding="utf-8"?>
<root>
    <a>
        a
    </a>
    <b>
        b
    </b>
    <c>
        c
    </c>
</root> 
if I delete <a> <b> using startRecording the source code turns into:
<?xml version="1.0" encoding="utf-8"?>
<root>


    <c>
        c
    </c>
</root>
left many blank and tab.How to solve it or I am in the wrong way?
Question 2:
in the transformer I also and some xinclude tag,like:
   attr.addAttribute(
    "http://www.w3.org/2001/XInclude",
    "href",
    "href",
    "CDATA",
    flowUri);
   super.startTransformingElement("", "include", "xi:include", attr);
   super.endTransformingElement("", "include", "xi:include");
   attr.clear();
the xml is fine,but can't be transform by XInclude transformer,but if I save the xml and use an another pipeline to use the xml in the disk,it can be transform by Xinclude.
If I use a xslt file to transform it first ,it can also transform by Xinclude.
So I believe it my transformer's problem,can you help?

Thanks advanced!

Roy Huang

Re: [Help]writing SAX Transformer

Posted by "J.Pietschmann" <j3...@yahoo.de>.
roy huang wrote:
...
> <root>
>     <a>
>         a
>     </a>
>     <b>
>         b
>     </b>
>     <c>
>         c
>     </c>
> </root> 
> if I delete <a> <b> using startRecording the source code turns into:
> <?xml version="1.0" encoding="utf-8"?>
> <root>
> 
> 
>     <c>
>         c
>     </c>
> </root>
> left many blank and tab. How to solve it or I am in the wrong way?
The whitespace is already there in the source (look
carefully). I don't think it hurts, and deleting it
selectively is not all that easy.

> Question 2:
> in the transformer I also and some xinclude tag,like:
>    attr.addAttribute(
>     "http://www.w3.org/2001/XInclude",
>     "href",
>     "href",
>     "CDATA",
>     flowUri);
>    super.startTransformingElement("", "include", "xi:include", attr);
>    super.endTransformingElement("", "include", "xi:include");
>    attr.clear();
> the xml is fine,but can't be transform by XInclude transformer,

I think you missed the namespace for the xi:include element, but
added the href attribute in the namespace instead. Try
    attr.addAttribute(
     "",
     "href",
     "href",
     "CDATA",
     flowUri);
    super.startTransformingElement("http://www.w3.org/2001/XInclude",
     "include", "xi:include", attr);
    super.endTransformingElement("http://www.w3.org/2001/XInclude",
     "include", "xi:include");
instead.
Dealing with namespaced elements and attributes in APIs is
tricky, study the topic carefully.

J.Pietschmann