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 Brian Frutchey <bf...@endeca.com> on 2005/10/05 00:27:53 UTC

Difficulty converting Stylesheet Class to XML String

I am attempting to build a quick JNI bridge between Xalan-J and Xalan-C++ such that a single-threaded windows application won't take so long to transform large mime messages with embedded base-64 encoded content (even with XSLTC a 12MB file takes 3 minutes and 85MB RAM to transform in Xalan-J, Xalan-C++ knocks it out in less than a second).  I am looking to pass the xml source, xslt, and result across the JNI interface as strings.  However, I can't understand how to get the org.apache.xalan.templates.Stylesheet class used by the TransformerFactoryImpl to build an XML string from its contents.  I built my own ContentHandler instead of using the org.apache.xalan.processor.StylesheetHandler, and I can simply build the XML String from the SAX events (which then works with my JNI interface), however I have difficulty supporting namespaces and am fairly certain I will never implement the w3c requirements in full, so it is not very good for general-use.  Hence I am wanting to override the existing xalan classes.  The only problem I seem to have is getting the Stylesheet out of the class as a string.  I tried treating the stylesheet as a node tree and walking it, but can't seem to find the root node (getParent() is always null).  Any ideas?  Thanks.

This email message and any attachments are confidential to Endeca. If you are not the intended recipient, please notify Endeca immediately -- by replying to this message or by sending an email to: legal@endeca.com -- and destroy all copies of this message and any attachments. Thank you.



Re: Difficulty converting Stylesheet Class to XML String

Posted by Brian Minchau <mi...@ca.ibm.com>.
Brian,
rather than build you own ContentHandler, have a look at:
http://xml.apache.org/xalan-j/public_apis.html

On that page are 3 links to the serializer's public APIs.
The last one, Serializer, ( see
http://xml.apache.org/xalan-j/apidocs/org/apache/xml/serializer/Serializer.html
 )
has an example of using the OutputPropertiesFactory and SerializerFactory
to obtain a Serializer
You can set your java.io.Writer or java.io.OutputStream on that Serializer,
then
send it SAX events to be written out as a stream of bytes (often an XML
File).

I'm not sure what format you stylesheet is in, but as a DOM you might
create a Serializer (as above),
then call the asDOMSerializer() method on it, to get a object through which
you can serializer the DOM,
see
http://xml.apache.org/xalan-j/apidocs/org/apache/xml/serializer/DOMSerializer.html

As of Xalan-J 2.7 the serializer is in its own jar, serializer.jar,
independent of the rest of Xalan-J.
A while ago performance work was put into this serializer.  It also tends
to keep only as much information
as it needs to, serializing elements as soon as it can, and dropping them
from memory after that.
This serializer is also namespace sensitive, so the SAX
startPrefixMapping() calls will work.

I'm not sure what you are trying to do with the you Stylesheet object.


- Brian
- - - - - - - - - - - - - - - - - - - -
Brian Minchau
XSLT Development, IBM Toronto
e-mail:        minchau@ca.ibm.com



                                                                           
             "Brian Frutchey"                                              
             <bfrutchey@endeca                                             
             .com>                                                      To 
                                       <xa...@xml.apache.org>      
             10/04/2005 06:27                                           cc 
             PM                                                            
                                                                   Subject 
                                       Difficulty converting Stylesheet    
                                       Class to XML String                 
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




I am attempting to build a quick JNI bridge between Xalan-J and Xalan-C++
such that a single-threaded windows application won't take so long to
transform large mime messages with embedded base-64 encoded content (even
with XSLTC a 12MB file takes 3 minutes and 85MB RAM to transform in
Xalan-J, Xalan-C++ knocks it out in less than a second).  I am looking to
pass the xml source, xslt, and result across the JNI interface as strings.
However, I can't understand how to get the
org.apache.xalan.templates.Stylesheet class used by the
TransformerFactoryImpl to build an XML string from its contents.  I built
my own ContentHandler instead of using the
org.apache.xalan.processor.StylesheetHandler, and I can simply build the
XML String from the SAX events (which then works with my JNI interface),
however I have difficulty supporting namespaces and am fairly certain I
will never implement the w3c requirements in full, so it is not very good
for general-use.  Hence I am wanting to override the existing xalan
classes.  The only problem I seem to have is getting the Stylesheet out of
the class as a string.  I tried treating the stylesheet as a node tree and
walking it, but can't seem to find the root node (getParent() is always
null).  Any ideas?  Thanks.


This email message and any attachments are confidential to Endeca. If you
are not the intended recipient, please notify Endeca immediately -- by
replying to this message or by sending an email to: legal@endeca.com -- and
destroy all copies of this message and any attachments. Thank you.