嗨,我有一个要求,我需要将新添加的child信息添加到单独的列中。 我赞扬同样,但面临一些问题。 截至目前,新添加的条目已添加到同一日期和versioninfo列,但我希望将此信息添加到单独的列中。
需要任何帮助。
谢谢
XML:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<DeviceHistory>
<Part Name="ERUI_Touch_LEFT">
<Details>
<Date>2019-01-28</Date>
<DeviceInfo>Firmware Version: -1</DeviceInfo>
<Date>2019-01-29</Date>
<DeviceInfo>Firmware Version: -2</DeviceInfo>
</Details>
</Part>
<Part Name="ERUI_Touch_RIGHT">
<Details>
<Date>2019-01-30</Date>
<DeviceInfo>Firmware Version: -1</DeviceInfo>
<Date>2019-01-31</Date>
<DeviceInfo>Firmware Version: -2</DeviceInfo>
</Details>
</Part>
</DeviceHistory>
xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0 "
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Part[@Name]/Details">
<html>
<body>
<table-header> <xsl:value-of select ="../@Name"/></table-header>
<table border="1" style="width:14cm">
<tr bgcolor="lightgray" margin-top="10pt">
<th>Date</th>
<td>
<td><xsl:apply-templates select="Date"/></td>
</td>
</tr>
<tr bgcolor="lightgray">
<th>VersionInfo</th>
<td>
<td><xsl:apply-templates select="DeviceInfo"/></td>
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:0)
这样尝试吗?
XSLT 1.0
<xsl:stylesheet version="1.0 "
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/DeviceHistory">
<html>
<body>
<xsl:apply-templates select="Part"/>
</body>
</html>
</xsl:template>
<xsl:template match="Part">
<h3>
<xsl:value-of select="@Name"/>
</h3>
<table border="1">
<tr>
<th>Date</th>
<xsl:apply-templates select="Details/Date"/>
</tr>
<tr>
<th>Version Info</th>
<xsl:apply-templates select="Details/DeviceInfo"/>
</tr>
</table>
</xsl:template>
<xsl:template match="Date | DeviceInfo">
<td>
<xsl:value-of select="."/>
</td>
</xsl:template>
</xsl:stylesheet>
应用于您的示例XML,结果将是:
<html><body>
<h3>ERUI_Touch_LEFT</h3>
<table border="1">
<tr>
<th>Date</th>
<td>2019-01-28</td>
<td>2019-01-29</td>
</tr>
<tr>
<th>Version Info</th>
<td>Firmware Version: -1</td>
<td>Firmware Version: -2</td>
</tr>
</table>
<h3>ERUI_Touch_RIGHT</h3>
<table border="1">
<tr>
<th>Date</th>
<td>2019-01-30</td>
<td>2019-01-31</td>
</tr>
<tr>
<th>Version Info</th>
<td>Firmware Version: -1</td>
<td>Firmware Version: -2</td>
</tr>
</table>
</body></html>
呈现为: