简体   繁体   中英

Best way to convert handlebars.js html template with template-literals into XSL-FO?

I'm in a situation where I need to convert a handlebars template into an XSL-FO document.

I understand that to convert an XHTML/HTML into XSL-FO, I can use a XSLT stylesheet to convert it, but I'm not sure how to handle this situation where I need to convert a mostly HTML file into XSL-FO.

<div>
    <p>
        {{ vehiclePrice }}
    </p>
    <p>
        Dealer Advertised Price
    </p>
</div>

There are also sections with

{{#if vehicle.image}}
    <p>Image may not represent actual vehicle.</p>
{{else if vehicle.dealer}}
    <p></p>

or in an attribute

<img src="{{baseUrl}}/template/images/image1.jpg" />

The approach I ultimately went with was to manually convert it to an XSL stylesheet first, and then try to transform it into an XSL-FO. But this doesn't seem really feasible, since the file I'm converting is >500 lines.

What are my options for programmatically converting a .handlebars file into a .xsl stylesheet?

If you can generate the HTML output from handlebars.js, you could transform the HTML without having to worry about handlebar.js constructs. You may need to run the HTML through HTML Tidy (or similar) to get XHTML that will work with XML tools.

If you have the BNF for the file that includes the handlebar.js constructs, then you might be able to create a parser ( https://www.bottlecaps.de/rex/ ) for the file and process that to, in effect, do what handlebar.js would do anyway. However, that is likely to be even more work that manually converting a single file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM