【问题标题】:Thymeleaf: XSL transformation on a XML documentThymeleaf:对 XML 文档的 XSL 转换
【发布时间】:2014-06-05 03:18:56
【问题描述】:

使用 Thymeleaf,如何将 xml 转换为 html。在jsp中我们可以使用x:transform jstl标签。

什么是 Thymeleaf 相当于下面的 jsp 代码:

<c:import url="/data/book.xml" var="inputvalue" />
<c:import url="/styles/book.xsl" var="stylesheet" />

<x:transform xml="${inputvalue}" xslt="${stylesheet}">
    <x:param name="bid" value="${bookId}" />
</x:transform>

【问题讨论】:

    标签: xml jsp xslt jstl thymeleaf


    【解决方案1】:

    我没有在 Thymeleaf 中找到 x:transform 的确切替换。

    但是,我发现了几种将 xsl 与 Thymeleaf 或任何其他模板引擎一起使用或不使用任何模板引擎的方法:

    1) 我们可以在服务器端使用 Saxon 等 xsl 处理器创建 html 字符串。然后在ui上显示:

    <P th:utext="${bookHtml}"></P>
    

    2) 我们可以在 Spring 中使用 XsltViewResolver。

    3)我们可以编写javascript代码将xml转换为html为explained here

    4) 大多数浏览器使用 xml 中提到的 xslt 将 xml 转换为 html,如下所示:

    <?xml-stylesheet type="text/xsl" href="book.xsl" ?>
    

    【讨论】:

    • 我正在检查是否可以在带有 xml 和 xsl 的项目中使用 Thymeleaf,这个答案促使我这样做。谢谢你! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-12
    • 1970-01-01
    • 2019-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多