xml - 如何通过 Xslt 转换转换 xml
问题描述
我有xml输出
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="/topic/get-all.xslt"?>
<List>
<item>
<id>8541915a-9098-4d10-bf80-5fbc9a5800af</id>
<name>TestTopfdic4</name>
<modifiedDate>2019-12-18T12:37:42.718</modifiedDate>
</item>
<item>
<id>55bc34e6-5cd2-436a-9d37-ceb1052187b0</id>
<name>TestTopfdic4</name>
<modifiedDate>2019-12-18T12:40:12.948</modifiedDate>
</item>
<item>
<id>2fee9ce3-1595-4c56-9833-cda03642ad05</id>
<name>TestTopfdic4</name>
<modifiedDate>2019-12-18T12:42:15.385</modifiedDate>
</item>
</List>
并尝试通过 xslt 将 tarnsform 转换为 html,我尝试选择每个项目并单独处理它
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/*">
<html>
<body>
<table align="center">
<thead>
<th>Id</th>
<th>Name</th>
<th>modified date</th>
</thead>
<tbody>
<xsl:for-each select="List">
<tr>
<td><xsl:value-of select="item.id"/></td>
<td><xsl:value-of select="item.name"/></td>
<td><xsl:value-of select="item.modifiedDate"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
但是得到空输出,我做错了什么?你能帮我解决这个问题吗?
解决方案
您的语法不是 XPath 语法。尝试:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/List">
<html>
<body>
<table align="center">
<thead>
<th>Id</th>
<th>Name</th>
<th>modified date</th>
</thead>
<tbody>
<xsl:for-each select="item">
<tr>
<td><xsl:value-of select="id"/></td>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="modifiedDate"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
推荐阅读
- javascript - Vue.js - “销毁”组件花费的时间太长
- eclipse - 在 Jenkins 上运行 gui 测试后获取 java.awt.HeadlessException
- regex - 正则表达式 AND 在由分隔符包围的块内搜索
- java - 如何在安卓中打开gmail
- xero-api - 更新现有联系人
- javascript - 我应该如何设置图像的类型?
- h2 - 为什么 h2 数据库在访问 h2 数据库时出现输入/输出错误?
- ios - 如何防止 ionic 3 应用程序冻结?
- java - 与 ExpandableListViews 有什么关系?
- hadoop - 无法启动配置单元,无法解析 [${clusterHostInfo/webhcat_server_host|append(core-site/hadoop.proxyuser.HTTP.hosts]