xml-xalan-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott_B...@lotus.com
Subject Re: Performance problems when passing node-set as global XSLT parameter
Date Tue, 31 Jul 2001 14:55:15 GMT

Hi Evan.  In 2.1.0 we used the DOM API raw.  That means that for certain
constructs, we would have to do document order comparisons by walking up
the ancestor chain.  There are some other issues also with using a foreign
DOM.  When you use the Document function, we can create our own optimized
DOM (Stree).  I think this is what you're seeing.

I'm curious what happens with your test with XalanJ 2.2.D8 (or the latest
CVS build).  (In 2.2.x we no longer use the DOM API internally, but instead
use the DTM [Document Table Model].  When you pass in a DOM, we have an
adapter to the DTM interface.)


                    "Evan Lenz"                                                          
                    <elenz@xyzfin        To:     <xalan-j-users@xml.apache.org> 
                    d.com>               cc:     (bcc: Scott Boag/CAM/Lotus)          
                                         Subject:     Performance problems when passing node-set
as global XSLT    
                    07/30/01             parameter                                       
                    08:23 PM                                                             

I have a situation where I want to repeatedly pass a large node-set, which
contains a set of root nodes from various documents, as a global XSLT
parameter into multiple stylesheets. The node-set stays the same and the
stylesheets change. For some reason, I'm having serious performance
when passing XNodeSet in as a parameter. In fact, in most cases it's faster
to re-parse the entire set of documents using the document() function
repeatedly at run-time! I'm using xalan-j_2_1_0.

Here are the relevant code snippets:

Example stylesheet:

<xsl:stylesheet version="1.0"

  <xsl:param name="foo"/>

<!-- using document() function works *much* faster, despite the need to
re-parse on the fly -->
<!-- <xsl:variable name="foo" select="document('a.xml') |
('b.xml')"/> -->

  <xsl:template match="/">
    <xsl:copy-of select="$foo//item"/>


First, I construct an instance of XNodeSet which contains a set of root

    private DocumentBuilderFactory bFactory;
    private Hashtable database = new Hashtable();
    private XNodeSet nodeSet;
    private File databaseDir;

. . .

        for (int i = 0; i < fileNames.length; i++)
            File file = new File(databaseDir, fileNames[i]);

            if (!file.isDirectory())
                DocumentBuilder builder = bFactory.newDocumentBuilder();
                Document doc = builder.parse(file);
                database.put(fileNames[i], doc);


        NodeSet tempNodeSet = new NodeSet();
        Enumeration enum = database.elements();
        while (enum.hasMoreElements())
        nodeSet = new XNodeSet(tempNodeSet);

. . .

Then, I repeatedly invoke different transformations using the same node-set
parameter. Each invocation takes approximately 8 times as long as if I were
to use the document() function, parsing the documents over and over again!

            transformer.setParameter("foo", nodeSet);
            transformer.transform(source, new StreamResult(out));

My expectation is that performance should be better constructing XNodeSet
once as opposed to invoking document() repeatedly, but exactly the reverse
is true! If anyone can tell me what's going on or point me to a different
object that I should be using (as opposed to XNodeSet), I'd greatly
appreciate it. I suspect that I should be building XNodeSet in a different
way (as opposed to accumulating DOM instances); I'd appreciate any
in how to do this.


Evan Lenz
XYZFind Corp.

View raw message