Here is state.java together with XML Catalog to bring everything together:
SAXBuilder stateBuilder = new SAXBuilder("org.ccil.cowan.tagsoup.Parser", false);
FileInputStream stateIS = new FileInputStream("E:\\state.xml");
BufferedInputStream stateBIS = new BufferedInputStream(stateIS);
Document stateOriginaljdomDocument = stateBuilder.build(stateBIS);
TransformerFactory stateFactory = TransformerFactory.newInstance();
FileInputStream styleSheetIS = new FileInputStream("E:\\stateStyleSheet.xsl");
BufferedInputStream styleSheetBIS = new BufferedInputStream(styleSheetIS);
Transformer stateTransformer = stateFactory.newTransformer(new StreamSource(styleSheetBIS));
Output from transformation process gives:
<?xml version="1.0" encoding="UTF-8"?>
<h2>Transformed State Detail</h2>
<th align="left">Area Link</th>
<th align="left">Area Name</th>
</html> [/code]I am not sure whether namespace has anything to do with it. The following XPath statement has worked on the same state.xml document:
Does that mean you still don't know how to declare a namespace in the root element of your XSLT?
Look at the root element you have now:
Notice that it already includes a namespace declaration. But that's not the namespace you're interested in. So just add another namespace declaration, for the namespace that you are interested in:
That's the namespace whose URI is "http://www.w3.org/1999/xhtml". Now in your input document, notice that you have two declarations for that namespace URI. One of them has no prefix (so it's the default namespace for the document) and the other has the "html" prefix. But both are the same namespace, so in that document the element "html" could also be called "html:html" without changing anything.
So in your XSLT, if you want to refer to elements in the input document whose names don't have prefixes (such as a "div" element for example), those elements are in the default namespace, since one is declared. But a "div" element is the same as an "html:div" element because the namespace is declared twice. And if you put that second declaration into your XSLT document, then the transformer knows about that namespace and it can access an "html:div" element in an XPath expression.
Now, remember that namespace prefixes aren't significant. The namespace URI is what counts. So in your XSLT you could have this instead:
Now to access a "div" element in your input document, your XPath expression would refer to "ns:div". Of course you could use any prefix you liked here.
posted 11 years ago
First of all, thank you very much for going through in detail on explaining how namespace work in XSLT. It is very much appreciated.
The error message produced is:
Exception in thread "main" org.jdom.IllegalNameException: The name "html:" is not legal for JDOM/XML Namespace prefixs: Namespace prefixes cannot contain colons.
....... It doesn't look as though XSLT accept "xmlns:html:="http://www.w3.org/1999/xhtml" namespace.
Many thanks for your patience and assistance again,