سؤال

I've got an arbitrary XHTML document which are usually not well formed, since websites can be made like that and browser will show it. How can I support XSLT translation for not well formed XHTML code? Is there a way that it can avoid those parts which are not well formed?

I have this code in Java, but as I've said it's not supporting not well formed XHTML:

try {
            TransformerFactory tFactory=TransformerFactory.newInstance();

            Source xslDoc=new StreamSource("path1");
            Source xmlDoc=new StreamSource("path2");

            String outputFileName="path3";

            OutputStream htmlFile=new FileOutputStream(outputFileName);
            Transformer trasform=tFactory.newTransformer(xslDoc);
            trasform.transform(xmlDoc, new StreamResult(htmlFile));
        } 
catch (Exception e) {...}
هل كانت مفيدة؟

المحلول

You can use JSoup library to parse and fix your HTML and then use XSLT.

نصائح أخرى

You can try to use an HTML parser like http://about.validator.nu/htmlparser/ or like TagSoup.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top