将带有模板文字的handlebars.js html模板转换为XSL-FO的最佳方法?
我现在的情况是需要将车把模板转换为 XSL-FO 文档。
我知道要将 XHTML/HTML 转换为 XSL-FO,我可以使用 XSLT 样式表来转换它,但我不确定如何处理这种需要将大部分 HTML 文件转换为 XSL-FO 的情况。
<div>
<p>
{{ vehiclePrice }}
</p>
<p>
Dealer Advertised Price
</p>
</div>
还有一些带有属性
{{#if vehicle.image}}
<p>Image may not represent actual vehicle.</p>
{{else if vehicle.dealer}}
<p></p>
或位于属性中的
<img src="{{baseUrl}}/template/images/image1.jpg" />
部分。我最终采用的方法是首先手动将其转换为 XSL 样式表,然后尝试将其转换为 XSL-FO。但这似乎不太可行,因为我要转换的文件超过 500 行。
以编程方式将 .handlebars
文件转换为 .xsl
样式表的选项有哪些?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您可以从handlebars.js 生成HTML 输出,则可以转换HTML,而不必担心handlebar.js 构造。您可能需要通过 HTML Tidy(或类似的)运行 HTML,以获得可与 XML 工具配合使用的 XHTML。
如果您有包含handlebar.js 构造的文件的 BNF,那么您也许能够创建一个解析器 (https://www.bottlecaps.de/rex/)用于文件并处理它,实际上,执行handlebar.js 无论如何都会执行的操作。然而,这可能比手动转换单个文件需要更多的工作。
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.