Skip to content

Don't use XSLT in report generator #909

Open

Description

@JukkaL

XSLT is not a widely used technology and pretty complex (and I don't want to learn it). We shouldn't rely on it in the report generator. Some reasonable alternatives include straight XML manipulation or JSON.

Activity

  1. o11c commented on Oct 12, 2015

    @o11c
    Contributor

    The thought behind my use of XSLT is: the primary report is now the machine-readable XML file. It is up to the user to decide how they want to view that - say, combine a python-cov report with a mypy report in a single report. For that motivating example, it is impossible for mypy to produce a meaningful HTML file, so the fact that XML files can be viewed directly with XSLT is a huge bonus (of course, nothing, but I think it's very valuable that we ship an example XSLT file).

    Plus (ignoring a little of the txt hackery which I did just to prove how flexible XSLT is, and some percentage calculations which we could precompute if we really had to), all the XSLT we use is pretty simple "get this part of the XML file, put it here in the output HTML file".

    Besides, I'm way more active than you are anyway.

    It's true that XSLT got less popular with the rise of languages like Markdown, but those are generally not machine-readable with arbitrary attributes like XML is.

    And XSLT actually works quite similarly to CSS, which lots of people know. (Possibly some CSS guru could even display the XML files directly without XSLT, but that doesn't mean it's a good idea).

  2. JukkaL commented on Oct 12, 2015

    @JukkaL
    CollaboratorAuthor

    I agree that technically XSLT does the job. It's just that I don't like it :-P

    Let's wait for more feedback -- maybe people are happy with it. First we should document how the report generator works, though.

  3. JukkaL commented on Oct 12, 2015

    @JukkaL
    CollaboratorAuthor

    Added #912 for documenting the report generator.

  4. refi64 commented on Oct 12, 2015

    @refi64
    Contributor

    Is there a reason you can't just use JSON? It's much easier (and faster) to parse.

  5. o11c commented on Oct 12, 2015

    @o11c
    Contributor

    If you're parsing it yourself, you're doing it wrong, use a library. You should treat XML (or JSON) as an opaque format that is only readable by special tools.

    JSON has a number of problems (limited unicode support, no integers, no standard schema tools, very poor tooling in general) that XML does not have.

  6. refi64 commented on Oct 12, 2015

    @refi64
    Contributor

    If you're parsing it yourself, you're doing it wrong, use a library.

    Exactly. I know of several languages that have built-in JSON parsers but not XML parsers. Writing an efficient XML parser is hard.

    limited unicode support

    ...yeah, you got me on this one. ;)

    no integers

    Huh? Aren't normal numbers good enough?

    no standard schema tools

    Not quite sure what this means...

    very poor tooling in general

    Does JSON even need that much tooling to begin with, though?

  7. o11c commented on Oct 12, 2015

    @o11c
    Contributor

    If you're parsing it yourself, you're doing it wrong, use a library.

    Exactly. I know of several languages that have built-in JSON parsers but not XML parsers. Writing an efficient XML parser is hard.

    Languages, just like end developers, shouldn't be writing their own JSON or XML parsers, but linking to a C implementation. JSON is merely a more tempting target.

    no integers

    Huh? Aren't normal numbers good enough?

    No. Floats are evil.

    no standard schema tools

    Not quite sure what this means...

    When mypy produces a report, it verifies that the XML nodes follow a certain structure. Besides preventing bugs in the generator, this allows tools that consume mypy XML files to automatically verify that they really are handling everything correctly.

    While there are a number of JSON schema tools, none is anywhere near even a de-facto standard.

    very poor tooling in general

    Does JSON even need that much tooling to begin with, though?

    A data language is useless without tooling.

    Show me a way to combine a python-cov report with a mypy report for the same file. It's easily possible with XSLT.

  8. refi64 commented on Oct 12, 2015

    @refi64
    Contributor

    Languages, just like end developers, shouldn't be writing their own JSON or XML parsers, but linking to a C implementation. JSON is merely a more tempting target.

    ...a C implementation which is almost always more painful. Not even Expat supports the entirety of XML. The parsers that support everything are huge and slow as heck.

    No. Floats are evil.

    Why? When doing arithmetic operations with integers stored as floats, the precision is perfectly fine.

  9. o11c commented on Oct 12, 2015

    @o11c
    Contributor

    ...a C implementation which is almost always more painful. Not even Expat supports the entirety of XML. The parsers that support everything are huge and slow as heck.

    lxml, which I used in mypy, is a great example of how to write a non-painful wrapper over a C library.

    And libxml2 comparse very favorably for performance, see http://lxml.de/performance.html

  10. refi64 commented on Oct 12, 2015

    @refi64
    Contributor

    You forgot the part where installing lxml on Windows is horribly broken.

  11. jhance commented on Oct 13, 2015

    @jhance
    Collaborator

    Using XSLT requires me to write XML therefore I will never use it

  12. o11c commented on Oct 13, 2015

    @o11c
    Contributor

    Using XSLT requires me to write XML therefore I will never use it

    That's what I said about XML until I used XSLT. In my opinion, XSLT tooling alone forgives all the human-unfriendliness from the rest of XML.

  13. JukkaL commented on Oct 14, 2015

    @JukkaL
    CollaboratorAuthor

    It seems like we have a consensus forming... XSLT is losing, unless it can gather some more support.

  14. ilinum commented on Jul 12, 2017

    @ilinum
    Collaborator

    I think we can use jinja2 instead of XSLT. It is more common than XSLT and so should be easier to use.

  15. gvanrossum commented on Nov 2, 2017

    @gvanrossum
    Member

    Do we still want to get rid of xslt? Then I think the jinja2 idea is a fine one. Would we completely lose the lxml dependency in favor of jinja2?

  16. JukkaL commented on Nov 2, 2017

    @JukkaL
    CollaboratorAuthor

    It would still be nice to get rid of the lxml dependency and I like the idea of using jinja2 instead. Jinja2 is much better known than XSLT in the Python community and it's also easier to learn, in my opinion.

  17. ilinum commented on Nov 2, 2017

    @ilinum
    Collaborator

    I think we can get rid of xslt if we switch to another jinja2.

    Coverage.py has their own template renderer that uses Django/Jinja2-like syntax. I wonder why they chose that over standard jinja2.

  18. gvanrossum commented on Nov 2, 2017

    @gvanrossum
    Member
  19. added a commit that references this issue on Jun 2, 2025
    557d964
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions