-1

This shouldn't be very complex, but I searched all over the internet and couldn't find such a tool.

This tool should take an XML or XSD file and generate an XSLT, When applying this XSLT to the XML, the result is a user-friendly HTML Page.

The developer then takes this program-generated XSLT and makes the necessary adjustments according to his requirements.

The benefits are obvious for huge XML files, you have something to work with, a "default" to start working on, instead of starting from scratch for a 3000 lines XML document.

KaBoZ85
  • 11
  • 1
  • 1
  • @zx485 I believe I understand exactly what XSLT is used for, what I'm asking for here is a solution to make it easier for the developers to focus on customizing their XSL instead of starting from scratch. If you have a suggestion or recommendation to such a sitiuation, I'ld like to hear it. If not, I'ld love to hear why. – KaBoZ85 Sep 10 '18 at 18:39
  • There are stylesheets for certain XML formats for transformation to HTML or other formats, like for DocBook or DITA. There are also stylesheets for generating an overview of an XSD schema, for instance if you load https://www.w3.org/TR/xslt-30/schema-for-xslt30.xsd in a browser it probably has applied https://www.w3.org/2008/09/xsd.xsl. You can adjust such stylesheet as well. How you expect to map arbitrary XML to "user-friendly HTML" I don't understand, unless you want to generate a tree representation, like browsers do if there is no associated stylesheet for an XML document. – Martin Honnen Sep 10 '18 at 19:02

1 Answers1

1

It is probably easiest to start with "XSLT identity transformation", which in its raw form looks like this:

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

It basically creates deep copy of the XML file, which is not very interesting as such, but it lets you decorate certain elements during that.

Depending on what how you wish the initial HTML look like, you can decorate it by adding specific templates, or altering the core recursive template to produce, let's say, nested <div> elements ... or <ul> / <li> or whatever.

This can be a simple start then:

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <ul>
            <xsl:apply-templates select="*"/>
        </ul>
    </xsl:template>
    <xsl:template match="@*|node()">
        <li>
        <xsl:value-of select="local-name()"/>
        <xsl:if test="*">
            <ul>
               <xsl:apply-templates select="@*|node()"/>
            </ul>
        </xsl:if>
        </li>
    </xsl:template>
</xsl:stylesheet>

You can play with anything then, at first you will probably want different rendering for attributes, then your well-known elements etc.

Petr Kozelka
  • 7,670
  • 2
  • 29
  • 44
  • Interesting that you use `version="3.0"` but then spell out that template, in XSLT 3 you can simply use ``. – Martin Honnen Sep 10 '18 at 19:04
  • you are right, I wanted it explicit to form a better base for improvements in the other example. – Petr Kozelka Sep 10 '18 at 19:10
  • Thanks Petr, actually I've seen this solution online and started experimenting with it, theoretically, it's ideal, but practically it doesn't solve much with all the deep nested elements and the loops and conditions, I'll still have to write all this code from scratch. For every loop to be displayed in a table for example – KaBoZ85 Sep 11 '18 at 11:27