XSLT transformation works only if namespace data is removed
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 8
- Joined: Sat May 08, 2004 8:38 am
- Contact:
XSLT transformation works only if namespace data is removed
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.
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.
-
- Posts: 8
- Joined: Sat May 08, 2004 8:38 am
- Contact:
JAXP defaults to being NON-namespace-aware
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:
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.
Code: Select all
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service