Evan --

The most likely cause of your functionality problem (as opposed to your
performance problem) is that you haven't set up bFactory with

  bFactory.setNamespaceAware(true);

This will allow the building of namespace-aware DOM trees.  Please let
me know if you're already doing this.

On the performance side, with 2.1.0, I'm not sure that the problem is. 
When you feed the file into XalanJ, rather than a DOM tree, XalanJ
builds its own proprietary tree called an stree which is more suitable
to XSLT work.  This may be accounting for the speed difference.

In XalanJ 2.2.x, this is changed again so that Xalan uses a DTM tree
which it builds one way for SAX events (also used for StreamSources fed
directly into Xalan) and which it builds a different way for DOM trees. 
You might try your performance issues here.

Also, you may want to build your own DTM trees and use those as part of
your XNodeSet.  That should improve performance considerably.

Gary

Evan Lenz wrote:
> 
> Hi Gary,
> 
> Thanks for the quick response. Yes, it appears that I made an incorrect
> assumption. It looks like the problem doesn't have anything to do with
> xalan:evaluate(). I am passing a node-set consisting of multiple root nodes
> (a "database" of documents) as a global parameter to my stylesheet using
> XNodeSet. So instead of the original stylesheet I posted, consider the
> following modified stylesheet (which doesn't use xalan:evaluate(), a red
> herring):
> 
> <xsl:stylesheet version="1.0"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>   xmlns:foo="http://dummyNamespace.com";>
> 
>   <xsl:param name="input"/>
> 
>   <xsl:template match="/">
>     <xsl:copy-of select="$input/foo:bar"/>
>   </xsl:template>
> 
> </xsl:stylesheet>
> 
> Below are some snippets from the code I am using to invoke this (some
> variables initialized elsewhere):
> 
>     private DocumentBuilderFactory bFactory;
>     private Hashtable database = new Hashtable();
>     private XNodeSet nodeSet;
>     private File databaseDir;
> 
> . . .
> 
>         String[] fileNames = databaseDir.list();
>         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())
>         {
>             tempNodeSet.addElement((Node)enum.nextElement());
>         }
>         nodeSet = new XNodeSet(tempNodeSet);
> 
> . . .
> 
>             transformer.setParameter("input", nodeSet);
>             transformer.transform(source, new StreamResult(out));
> 
> I have two serious problems with the node-set that's being passed in: 1)
> namespaces don't work correctly, and 2) performance is horrible (worse than
> if I were to parse the documents repeatedly using the document() function).
> 
> I posted a message to xalan-j-users earlier today about the performance
> problem, but it seems to have the same root as my problem with XPath queries
> using namespaces.
> 
> My fundamental question is: What is the recommended way to construct an
> arbitrary XPath node-set in order to pass it in as the value of a global
> XSLT parameter? I have been using XNodeSet() with NodeSet() and a sequence
> of DOM trees. I suspect that DOM is losing the namespace information,
> although successful transformations still serialize the original namespace
> prefixes that were used.
> 
> Any help would be greatly appreciated.
> 
> Thanks,
> 
> Evan Lenz
> XYZFind Corp.

Reply via email to