XSLT transformation works only if namespace data is removed

Questions about XML that are not covered by the other forums should go here.
greggw
Posts: 8
Joined: Sat May 08, 2004 8:38 am
Contact:

XSLT transformation works only if namespace data is removed

Post by greggw »

Hi--I have a problem that I hope someone can give me some help with. I'm sure that I must be missing something very simple, but despite weeks of research and debugging, I can't figure out what it is.

I've built a standalone Java application that takes input from a window, then uses that data to create a schema-based XML file. In addition, the program can read such an XML file, apply an XSLT transformation, and write the resulting output to another file.

Here's the behavior that I observe:

* When I transform an appropriate XML document with my XSLT file (which, remember, is namespace-aware) using the oXygen development environment, I get the output text that I want.

* When I transform the same document using the same XSLT file from within my Java application (using methods from the appropriate javax.xml.transform... packages), I get an empty output.

* I then copy my XSLT file and take all of the namespace information out of the copy. When I transform the same document using this namespace-blind but otherwise equivalent XSLT file, I again get the output text that I want.

To summarize, my question is this: Why does the namespace-aware XSLT file work when applied on its own (using Xalan or Saxon) but not when the same XSLT file is used to process the same source XML file within my standalone Java application?

I can post program details if needed. Thank you for your help.
greggw
Posts: 8
Joined: Sat May 08, 2004 8:38 am
Contact:

JAXP defaults to being NON-namespace-aware

Post by greggw »

I finally found the answer to my question at http://people.apache.org/~edwingo/jaxp- ... nsDefaults. It turns out that, when using JAXP (which I was), default is to be NON-namespace-aware. The solution is to set the proper bit for namespace-awareness NOT in the creation of the TransformerFactory, but in the creation of the DocumentBuilderFactory, as follows:

Code: Select all

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
What threw me was that it didn't occur to me to search the API for anything but the Transformer and the TransformerFactory ((sigh)). I hope that posting this will help someone else struggling with this problem.
Post Reply