Hi Michael,
By replacing the FileReader with InputStream the following codes has
finally allow me to read and transformed state.xml to state.html but
only when there is an Internet Online connection:
19. SAXBuilder stateBuilder = new
SAXBuilder("org.ccil.cowan.tagsoup.Parser", false);
20. stateBuilder.setValidation(false);
21. FileInputStream stateIS = new FileInputStream("E:\\state.xml");
22. BufferedInputStream stateBIS = new BufferedInputStream(stateIS);
23. Document stateOriginaljdomDocument = stateBuilder.build(stateBIS);
24. TransformerFactory stateFactory = TransformerFactory.newInstance();
25. Transformer stateTransformer = stateFactory.newTransformer(new
StreamSource("E:\\stateStyleSheet.xsl"));
26. JDOMSource stateSource = new JDOMSource(stateOriginaljdomDocument);
27. JDOMResult stateResult = new JDOMResult();
28. stateTransformer..transform(stateSource, stateResult);
......
Offline
javax.xml.transform.TransformerException: org.jdom.JDOMException: DTD
parsing error: www.w3.org
at
org.apache.xalan.transformer.TransformerImpl.fatalError(TransformerImpl.java:738)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:712)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1126)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1104)
at XMLProject.main(generateXML.java:28)
Caused by: org.jdom.JDOMException: DTD parsing error: www.w3.org
at
org.jdom.transform.JDOMSource$DocumentReader.parse(JDOMSource.java:525)
at
org.apache.xml.dtm.ref.DTMManagerDefault.getDTM(DTMManagerDefault.java:478)
at
org.apache.xalan.transformer..TransformerImpl.transform(TransformerImpl.java:655)
... 3 more
It appears that the transformation process is trying to validate DTD even
though I have turned validation off during parsing. Can you confirm whether
the validation attempt is occurring during parsing or transformation step? And
how to prevent it from recurring?
At the sametime, the content of state.html is:
<?xml version="1.0" encoding="UTF-8"?>
<html>
<body>
<h2>Transformed State
Detail</h2>
<table
border="1">
<tr
bgcolor="lightblue">
<th
align="left">Area
Link</th>
<th
align="left">Area
Name</th>
</tr>
</table>
</body>
</html>
This means that the stateStyleSheet..xsl below is not able to use XPath
search to retrieve both Area Link and Area
Name from state.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Transformed State Detail</h2>
<table border="1">
<tr bgcolor="lightblue">
<th align="left">Area Link</th>
<th align="left">Area Name</th>
</tr>
<xsl:for-each
select="/html/body/div[@id='content']/table[@class='sresults']/tr/td/a">
<tr>
<td><xsl:value-of select="@href"/></td>
<td><xsl:value-of select="@title"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Again, the following XPath search statements have found Area
Link, Area Name from state.xml:
XPath stateXpath =
XPath.newInstance("/ns:html/ns:body/ns:div[@id='content']/ns:table[@class='sresults']/ns:tr/ns:td/ns:a");
stateXpath.addNamespace("ns", "http://www.w3.org/1999/xhtml");
In short, how to include the implicit/explicit/both namespace to accurately
pick up these values from within stateStyleSheet.xsl?
Many thanks again for your valuable advice,
Jack