简体   繁体   English

将带有模板文字的 handlebars.js html 模板转换为 XSL-FO 的最佳方法?

[英]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.我处于需要将车把模板转换为 XSL-FO 文档的情况。

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.我知道要将 XHTML/HTML 转换为 XSL-FO,我可以使用 XSLT 样式表来转换它,但我不确定如何处理这种情况,我需要将大部分 HTML 文件转换为 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.我最终采用的方法是首先将其手动转换为 XSL 样式表,然后尝试将其转换为 XSL-FO。 But this doesn't seem really feasible, since the file I'm converting is >500 lines.但这似乎不太可行,因为我正在转换的文件超过 500 行。

What are my options for programmatically converting a .handlebars file into a .xsl stylesheet?以编程方式将.handlebars文件转换为.xsl样式表的选项有哪些?

If you can generate the HTML output from handlebars.js, you could transform the HTML without having to worry about handlebar.js constructs.如果您可以从 handlebars.js 生成 HTML output,则可以转换 HTML 而不必担心 handlebar.js 构造。 You may need to run the HTML through HTML Tidy (or similar) to get XHTML that will work with XML tools.您可能需要运行 HTML 到 HTML Tidy(或类似工具)以获得可与 XML 工具一起使用的 XHTML。

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.如果您拥有包含 handlebar.js 结构的文件的 BNF,那么您可以为该文件创建一个解析器 ( https://www.bottlecaps.de/rex/ ) 并对其进行处理,实际上,做 handlebar.js 无论如何都会做的事情。 However, that is likely to be even more work that manually converting a single file.但是,与手动转换单个文件相比,这可能需要更多工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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