[Home] [By Thread] [By Date] [Recent Entries]
I wrote a small JAXP program (using the EntityResolver approach I wrote), which I think could be useful to you. The XML file is (named dtdexp.xml): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>simple document</title> </head> <body> <p>a simple paragraph</p> </body> </html> The stylesheet used is (an identity transform) - named dtdexp.xsl: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" indent="yes" /> <xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template></xsl:stylesheet> When run with Saxon (or Xalan-J) normally, following error message is produced: Error java.net.ConnectException: Connection timed out: connect Transformation failed: Run-time errors were reported Now I've written a utility Java class, using JAXP as below: import java.io.*; import org.w3c.dom.*; import org.xml.sax.*; import javax.xml.parsers.*; import org.xml.sax.*; import org.xml.sax.helpers.*; import org.apache.xerces.jaxp.*; import javax.xml.transform.*; import javax.xml.transform.stream.*; import javax.xml.transform.dom.*; public class MyTransform implements EntityResolver { public static void main(String[] args)
{ String xmlfile = args[0];
String xslfile = args[1];MyTransform obj = new MyTransform(); try {
DocumentBuilderFactoryImpl factory = new DocumentBuilderFactoryImpl();
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(obj);Document document = builder.parse(xmlfile); TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer transformer = tfactory.newTransformer(new
StreamSource(xslfile));
transformer.transform(new DOMSource(document), new
StreamResult(new OutputStreamWriter(System.out))); }
catch(Exception ex) {
ex.printStackTrace();
}
} public InputSource resolveEntity(java.lang.String publicId,
java.lang.String systemId)
{InputSource is = new InputSource(new StringReader("")); return is; } } When this is run as: java MyTransform dtdexp.xml dtdexp.xsl The output produced is: <html> <head> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>simple document</title> </head> <body> <p>a simple paragraph</p> </body> </html> The Java class gets rid of DTD reference before applying the XSLT transformation. Regards, Mukul On 7/11/06, dvint@xxxxxxxxx <dvint@xxxxxxxxx> wrote: This is the first time I've had to process XHTML files with XSLT. I'm using saxon and getting an error that it can't find the DTD referenced in the file that I'm processing. File has:
|

Cart



