You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Stéphane Conversy <co...@cena.fr> on 2005/10/10 11:41:59 UTC
dom2dom: producing specialized nodes
Hello,
I'm trying to use xalan to transform a dom to another dom, which in
turn defines an svg scene for batik. But I want the second dom to be
built using batik's own DOM implementation.
I tried to pass a dom node from batik to a DOMResult during the
creation of DOMResult, but I only get "generic" dom elements, which are
ignored by the batik rendering process.
here is the xsl:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="button">
<rect x="10" y="20" width="150" height="100" style="fill:green"/>
</xsl:template>
</xsl>
I checked that the <rect> element appears in the result tree, and I
even added another (red) rectangle element by hand using batik dom
implementation.
I have no run-time error, but only the red rectangle (added by hand) is
displayed.
I guess this has something to do with namespaces (?).
any cues ?
s.
--
stéphane conversy
http://www.tls.cena.fr/~conversy
Re: dom2dom: producing specialized nodes
Posted by Stéphane Conversy <co...@cena.fr>.
Le 10 oct. 05, à 22:00, Joseph Kesselman a écrit :
>> if I pass a document Node, I get an error during the transformation
>> process, it denies the creation of a new element directly under the
>> document node.
>
> Document nodes became relatively immutable in DOM Level 2 (though
> that's
> relaxed slightly in DOM Level 3) for reasons related to subclassing of
> the
> DOM. If you're working with a DOM that does not permit altering the
> Document node's root element, you can't pass in a Document node and
> have
> this work.
>
> I believe there is an outstanding wishlist item to change DOMResult so
> we
> could pass in a DOMImplementation and possibly a DocumentType (or
> retrieve
> those from a sample Document node) , and use the
> DOMImplementation.createDocument() method to properly create a new DOM
> tree. But I don't think that's been implemented yet. This shouldn't be
> hard
> to code up; if someone wants to sketch a solution and submit it,
> that'd be
> great...
I do not have much time, if I run into performance problem because of
this 2 steps procedure, I may have a look at it...
>
> Workaround: Build into a DocumentFragment, and postprocess to
> re-instantiate the root element in a new document and use importNode to
> migrate the element's contents into that new element node. If the new
> DOM
> is in the same implementation as the old one, most DOMs are able to
> migrate
> the nodes over without having to recreate them, so this is annoying
> but not
> expensive.
Actually, when Batik's JSVGCanvas.setDocument(Document) is called,
Batik checks if the passed document is its own implementation.
If so it uses it as is, otherwise it clones it, as you suggest to do.
>
> If I remember correctly, DOM Level 3 may (or may not, implementation
> dependent due to the same subclassing issues) permit creating an empty
> Document node and then adding to it. We'll still want the
> build-via-DOMImplementation support added, though.
>
> ______________________________________
> Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
> "The world changed profoundly and unpredictably the day Tim Berners Lee
> got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk
>
--
stéphane conversy
http://www.tls.cena.fr/~conversy
Re: dom2dom: producing specialized nodes
Posted by Joseph Kesselman <ke...@us.ibm.com>.
>if I pass a document Node, I get an error during the transformation
>process, it denies the creation of a new element directly under the
>document node.
Document nodes became relatively immutable in DOM Level 2 (though that's
relaxed slightly in DOM Level 3) for reasons related to subclassing of the
DOM. If you're working with a DOM that does not permit altering the
Document node's root element, you can't pass in a Document node and have
this work.
I believe there is an outstanding wishlist item to change DOMResult so we
could pass in a DOMImplementation and possibly a DocumentType (or retrieve
those from a sample Document node) , and use the
DOMImplementation.createDocument() method to properly create a new DOM
tree. But I don't think that's been implemented yet. This shouldn't be hard
to code up; if someone wants to sketch a solution and submit it, that'd be
great...
Workaround: Build into a DocumentFragment, and postprocess to
re-instantiate the root element in a new document and use importNode to
migrate the element's contents into that new element node. If the new DOM
is in the same implementation as the old one, most DOMs are able to migrate
the nodes over without having to recreate them, so this is annoying but not
expensive.
If I remember correctly, DOM Level 3 may (or may not, implementation
dependent due to the same subclassing issues) permit creating an empty
Document node and then adding to it. We'll still want the
build-via-DOMImplementation support added, though.
______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk
Re: dom2dom: producing specialized nodes
Posted by Stéphane Conversy <co...@cena.fr>.
Le 10 oct. 05, à 19:55, Joseph Kesselman a écrit :
> What _kind_ of node are you passing into DOMResult. Generally, as the
> setNode method notes, it should be a Document node -- if your DOM
> implementation permits adding top-level nodes to the Document, not all
> do
> -- or an Element node, or a DocumentFragment node. Xalan's output
> should be
> constructed as descendants of that node.
if I pass a document Node, I get an error during the transformation
process, it denies the creation of a new element directly under the
document node.
This is the Batik implementation.
>
> ______________________________________
> Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
> "The world changed profoundly and unpredictably the day Tim Berners Lee
> got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk
>
--
stéphane conversy
http://www.tls.cena.fr/~conversy
Re: dom2dom: producing specialized nodes
Posted by Joseph Kesselman <ke...@us.ibm.com>.
What _kind_ of node are you passing into DOMResult. Generally, as the
setNode method notes, it should be a Document node -- if your DOM
implementation permits adding top-level nodes to the Document, not all do
-- or an Element node, or a DocumentFragment node. Xalan's output should be
constructed as descendants of that node.
______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk