You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by Steve Dussinger <sd...@adobe.com> on 2004/05/27 04:36:52 UTC
Stylesheet in a Xerces DOM tree?
I've got a XSL stylesheet which was preparsed by Xerces as part of the
initialization of my application. I need to be able to pass that DOM
tree to the transformer to run the transformation.
So far I've been unable to figure out how to get it to work. What I
want is something like this:
Xercesc_2_5::DOMElement *stylesheet; // This was parsed earlier by
Xerces duing my program initialization
Xercesc_2_5::DOMDocument *sourceDoc; // The DOM document I want to
transform
Xercesc_2_5::DOMDocument *outputDoc; // The DOM document I want the
results placed in.
XalanTransformer transformer;
// transform the sourceDoc. In reality if I can only get a string
back as the output of the transform,
// I'm not as concerned but I really need to pass the DOMDocument
(or element) as the stylesheet.
Transformer.transform (sourceDoc, stylesheet, outputDoc);
Is anything like this possible? Or do I have to convert my xerces-parsed
DOM tree back to a string and let Xalan re-parse it?
Any pointers would be appreciated.
Thanx,
Steve Dussinger
Re: Stylesheet in a Xerces DOM tree?
Posted by Holger Flörke <fl...@doctronic.de>.
Hi Steve,
I use a XercesDOM as the xml input for transformations, but I think this
would be the same for the input of a XercesDOM stylesheet.
To do so, you have to wrap the XercesDOM with a XalanDOM interface. This is
the task of the class XercesDOMWrapperParsedSource. This class is inherited
from XalanParsedSource, you can use it as the source input for the
XalanTransformer::transform method (see the "ParsedSourceWrappers" example
provided by xalan). The stylesheet parameter of the transform method does
not accept a XalanParsedSource, but you can get a XalanDocument* out of the
XalanParsedSource and create a XSLTInputSource object with it (see the
Xalan-API for more details). I haven't tried the wrapping of a stylesheet,
yet.
HolgeR
Steve Dussinger schrieb:
> I've got a XSL stylesheet which was preparsed by Xerces as part of the
> initialization of my application. I need to be able to pass that DOM
> tree to the transformer to run the transformation.
>
> So far I've been unable to figure out how to get it to work. What I
> want is something like this:
>
> Xercesc_2_5::DOMElement *stylesheet; // This was parsed earlier by
> Xerces duing my program initialization
> Xercesc_2_5::DOMDocument *sourceDoc; // The DOM document I want to
> transform
> Xercesc_2_5::DOMDocument *outputDoc; // The DOM document I want the
> results placed in.
>
> XalanTransformer transformer;
>
> // transform the sourceDoc. In reality if I can only get a string
> back as the output of the transform,
> // I'm not as concerned but I really need to pass the DOMDocument
> (or element) as the stylesheet.
> Transformer.transform (sourceDoc, stylesheet, outputDoc);
>
> Is anything like this possible? Or do I have to convert my xerces-parsed
> DOM tree back to a string and let Xalan re-parse it?
>
> Any pointers would be appreciated.
>
> Thanx,
> Steve Dussinger
>
>
>
--
holger floerke d o c t r o n i c
email floerke@doctronic.de information publishing + retrieval
phone +49 2222 9292 90 http://www.doctronic.de
Re: Stylesheet in a Xerces DOM tree?
Posted by da...@us.ibm.com.
> I've got a XSL stylesheet which was preparsed by Xerces as part of the
> initialization of my application. I need to be able to pass that DOM
> tree to the transformer to run the transformation.
>
> So far I've been unable to figure out how to get it to work. What I
> want is something like this:
>
> Xercesc_2_5::DOMElement *stylesheet; // This was parsed earlier by
> Xerces duing my program initialization
> Xercesc_2_5::DOMDocument *sourceDoc; // The DOM document I want to
> transform
> Xercesc_2_5::DOMDocument *outputDoc; // The DOM document I want the
> results placed in.
>
> XalanTransformer transformer;
>
> // transform the sourceDoc. In reality if I can only get a string
> back as the output of the transform,
> // I'm not as concerned but I really need to pass the DOMDocument
> (or element) as the stylesheet.
> Transformer.transform (sourceDoc, stylesheet, outputDoc);
>
> Is anything like this possible? Or do I have to convert my xerces-parsed
> DOM tree back to a string and let Xalan re-parse it?
Yes, it's certainly possible. You need to wrap the Xerces-C stylesheet DOM
tree in the same way you wrap the Xerces-C source DOM tree. Then, you can
construct the stylesheet's XSLTInputSource with that wrapped tree. If your
stylesheet has imports and/or includes, you should also set the system ID
on the stylesheet XSLTInputSource so the parser can resolve any relative
URI references correctly.
There are two ways to do this. The first is to create an instance of
XercesDOMWrapperParsedSource and use the getDocument() accessor function to
get the underlying XalanDocument instance. Another way, which can be more
efficient, is to create your own instances of XercesParserLiaison and
XercesDOM support and do what the constructor of
XercesDOMWrapperParsedSource does. That's better if you plan to do
multiple transformations, because you can re-use the XercesParserLiaison
and XercesDOM instances. For more information about using
XercesDOMWrapperParsedSource, see the sample "ParsedSourceWrappers."
You can also transform to an instance of the Xerces-C DOM provided your
stylesheet produces a well-formed XML document. See the sample
"TransformToXercesDOM" for more information.
Dave