我正在使用 xslt 在 xml 文件上应用一些模板并输出 html 页面。所以我将'xsl:output'的方法定义为'html'。但是,我需要以原始格式显示 xml 文件中的一些 xml 节点,不幸的是,它们并没有像我预期的那样出现在 html 页面上。
这是示例 xml 文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<employees>
<employee>
<name>Hello World</name>
<title>UI Designer</title>
</employee>
</employees>
我的xslt如下:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<title>Example of Employee Data</title>
</head>
<body>
<h2>The following shows the structure of employee data file: </h2>
<div style="background-color: grey">
<xsl:copy-of select="employees/employee"/>
</div>
......
</body>
</html>
</xsl:template>
</xsl:stylesheet>
当我查看页面源代码时,节点“employee”及其子节点在那里,只是没有显示在 html 页面中。我认为这是因为我将输出方法指定为“html”。但是我必须生成一个 html 页面并将一些 xml 格式的节点嵌入到我的页面中......
我一直在尝试但失败了...有人可以帮我吗?谢谢!!
我希望输出页面是:
最佳答案
这可能有点晚了,但我最终在这个页面上寻找完全相同的东西。
通过 XLST 在 HTML 页面上复制 XML 数据的一种非常简单的方法是使用框架。我找到了这个解决方案 here ,显然它已过时且已弃用,但我刚刚测试过并且它正在运行。
<xmp>
<xsl:copy-of select="."/>
</xmp>
正如您从屏幕截图中看到的,我在下面有一个带有 XML 数据的漂亮 Accordion !
关于html - 如何使用 xslt 在 html 页面中显示一些 xml 节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15752617/