0

I am nearly finished with a program to convert HTML to a PDF format. My issue is more specific than this program though. I have an XSL file that is giving me some grief when I try to use it with my program.

When using javax.xml.transform.Transformer.transform(source, result) I am getting the following warning and error messages due to my XSL styleSheet:

Compiler Warnings: Attribute 'leader-length' outside of element.
ERROR: 'Error(Unknown location): fo:list-item is not a valid child element of fo:block.'

The XSL file in question can be found here: http://webcoder.info/downloads/xhtml2fo.html

It is recommended by this tutorial: https://blogs.oracle.com/chrisf/entry/converting_html_to_pdf_using

Any assistance with what/where these error messages are coming from would be of great help! I am totally unfamiliar with XSL files.

Thank you so much.

EDIT: I suppose it is possible that something else is at fault. Using other XSL files, I get: "Document is empty (Something might be wrong with your XSLT stylesheet)" However, I am following the Oracle tutorial pretty much to the letter. Does he have a bug in his code? (Within the link above.)

EDIT2: I should have posted this in the first place: http://webcoder.info/downloads/xhtml2fo.xsl

If that link isn't working, I'll paste in the exact code here. Thanks!

EDIT3: This is some of the HTML I am trying to use as an example: http://docs.oracle.com/javase/1.4.2/docs/tooldocs/solaris/classpath.html

BlackVegetable
  • 12,594
  • 8
  • 50
  • 82
  • 1
    The actual error (not the warning) is an XSL-FO error. List items are trying to be output in an `fo:block`. Can you post your input HTML? – Daniel Haley May 22 '12 at 19:53
  • All but the simplest HTML pages are having issues with the list(s). What do I need to change in the XSL file? It seems very complicated and is a bit over my head. – BlackVegetable May 22 '12 at 21:57
  • 1
    I can't tell what needs to be changed until I can reproduce the error. The "classpath.html" in EDIT3 is not even close to well-formed so it can't be treated as XML which is what XSLT needs to be able to process. Do you have another example that can be processed by the XSLT? – Daniel Haley May 23 '12 at 03:17
  • Within the code, I am using HTMLCleaner (2.2) which is supposed to take HTML input and clean it up to be well-formed XML. Now the example is using v2.1 which may be a source of error, but I cannot find where a place to download 2.1 . I don't think it is working at the moment. – BlackVegetable May 23 '12 at 13:54
  • I can't help directly, but there are a strong recommendation to check "CSS+XHTML to PDF" technologies in your future work, see [Why use XSL-FO instead of CSS2, for transform HTML into good PDF?](http://stackoverflow.com/q/10641667/287948). I was studying XSL-FO and CSS since of the post, and concluded that, for near future, the CSS2 for paged media is the best solution for any XML-Publishing pipeline. All XML tools (from author-tools and editors to mass-production tools) are compatible with XHTML and CSS standards, and there are many mature tools and people working with it. – Peter Krauss Jul 26 '12 at 19:36

1 Answers1

1

On the line before <fo:leader ... /> should not have that slash /.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • You know, I'm not actually seeing a line with any slash before Could you possibly give me a number for that line? Thanks for your help. – BlackVegetable May 22 '12 at 17:56
  • 1
    Search for `leader-length` and then the line before. – Joop Eggen May 22 '12 at 18:46
  • That fixes the warning, but not the error. Thanks for your help so far. – BlackVegetable May 22 '12 at 19:00
  • 1
    Post your XML and I'll be able to help you. Just for understanding: The XSLT stylesheet was written by someone else? – Dabbler May 22 '12 at 19:08
  • Correct. Rather than clutter up the question, would it be easier for you to follow the first link I posted? It leads to an html page containing the XML. I can delete a small piece and remove the complier warning but it doesn't affect the ERROR that crashes my program. – BlackVegetable May 22 '12 at 19:31
  • Hmm, did you mean the XML representation of the HTML page I am working with? If so, I am just using any old page. But I think you meant the XSL (which is a kind of XML?) – BlackVegetable May 22 '12 at 19:37
  • 1
    I meant the input XML for the transformation (which I suppose is XHTML). Technically, the problem is that the `list-item` must be inside a `list-block`. But that error could be due to either a bug in the XSLT or to your XHTML, so I need the actual XHTML to find out. – Dabbler May 22 '12 at 20:17
  • I have been trying to get this code to work on *any* HTML page so far. My code is basically the exact same as that in the second link I provided. If you have an example HTML (XHTML?) page that you think would be good and simple to try, I'd love to see it. I'm very confused with this project. – BlackVegetable May 22 '12 at 20:35
  • Alright, now I feel foolish. My (his) code works but not for every HTML file. How can I tell if an HTML file is not going to jive with my XSL document (and do I need to open up a new "question" for this?) – BlackVegetable May 22 '12 at 20:39
  • Well, the problem occurs with lists, so any XHTML that does not contain lists will not have this problem. But you really need to provide the XHTML. The link you posted does not contain any. Apparently it's built dynamically from some HTML, but the HTML is not shown, either. – Dabbler May 22 '12 at 20:41
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/11601/discussion-between-dabbler-and-blackvegetable) – Dabbler May 22 '12 at 20:45