我有下面的 XML 文件,我正在尝试为其创建一个 XSLT 模板来将一些节点制成表格。请有人可以帮助我。
<Main>
<Document>Doc.1</Document>
<Cini>DDFR</Cini>
<List>
<SubList>
<CdTa>ABC</CdTa>
<NN>XYZ</NN>
<ND>
<RiS>
<RiN>
<NSE14>
<MNRs>
<MRD>
<NR>
<N1>393</N1>
<N2>720</N2>
<SNR>
<NR_i>203</NR_i>
<NR_f>49994</NR_f>
</SNR>
</NR>
</MRD>
<MRD>
<NR>
<N1>687</N1>
<N2>345</N2>
<SNR>
<NR_i>55005</NR_i>
<NR_f>1229996</NR_f>
</SNR>
</NR>
</MRD>
</MNRs>
<GNRs>
<RD>
<NR>
<N1>649</N1>
<N2>111</N2>
<SNR>
<NR_i>55400</NR_i>
<NR_f>877</NR_f>
</SNR>
</NR>
</RD>
</GNRs>
<MSNRs>
<NR>
<N1>748</N1>
<N2>5624</N2>
<SNR>
<NR_i>8746</NR_i>
<NR_f>7773</NR_f>
</SNR>
</NR>
<NR>
<N1>124</N1>
<N2>54</N2>
<SNR>
<NR_i>8847</NR_i>
<NR_f>5526</NR_f>
</SNR>
</NR>
</MSNRs>
</NSE14>
<NSE12>
<MBB>990</MBB>
<MRB>123</MRB>
</NSE12>
<MGE13>
<TBB>849</TBB>
<TRB>113</TRB>
</MGE13>
</RiN>
</RiS>
</ND>
</SubList>
</List>
</Main>
这个 XSLT 代码
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr bgcolor="#FFF833">
<th style="text-align:left">MNRs</th>
<th style="text-align:left">GNRs</th>
<th style="text-align:left">MSNRs</th>
</tr>
<tr bgcolor="#9acd32">
<th style="text-align:left">N1</th>
<th style="text-align:left">N2</th>
<th style="text-align:left">NR_i</th>
<th style="text-align:left">NR_f</th>
<th style="text-align:left">N1</th>
<th style="text-align:left">N2</th>
<th style="text-align:left">NR_i</th>
<th style="text-align:left">NR_f</th>
<th style="text-align:left">N1</th>
<th style="text-align:left">N2</th>
<th style="text-align:left">NR_i</th>
<th style="text-align:left">NR_f</th>
</tr>
<xsl:for-each select="//MNRs//NR">
<tr>
<td><xsl:value-of select="N1"/></td>
<td><xsl:value-of select="N2"/></td>
<xsl:for-each select="SNR">
<td><xsl:value-of select="NR_i"/></td>
<td><xsl:value-of select="NR_f"/></td>
</xsl:for-each>
</xsl:for-each>
<xsl:for-each select="//GNRs//NR">
<td><xsl:value-of select="N1"/></td>
<td><xsl:value-of select="N2"/></td>
<xsl:for-each select="SNR">
<td><xsl:value-of select="NR_i"/></td>
<td><xsl:value-of select="NR_f"/></td>
</xsl:for-each>
</xsl:for-each>
<xsl:for-each select="//MSNRs//NR">
<td><xsl:value-of select="N1"/></td>
<td><xsl:value-of select="N2"/></td>
<xsl:for-each select="SNR">
<td><xsl:value-of select="NR_i"/></td>
<td><xsl:value-of select="NR_f"/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
使用当前的 XSLT 代码,我得到的输出不是我想要获得的结构,因为我只得到了一些值。问题是有 3 个父节点具有相同的子节点名称。父节点是 MNRs、GNRs 和 MSNRs
+------+------+-------+---------+----+----+------+------+----+----+------+------+
| MNRs | GNRs | MSNRs | | | | | | | | | |
+------+------+-------+---------+----+----+------+------+----+----+------+------+
| N1 | N2 | NR_i | NR_f | N1 | N2 | NR_i | NR_f | N1 | N2 | NR_i | NR_f |
+------+------+-------+---------+----+----+------+------+----+----+------+------+
| 393 | 720 | 203 | 49994 | | | | | | | | |
+------+------+-------+---------+----+----+------+------+----+----+------+------+
| 687 | 345 | 55005 | 1229996 | | | | | | | | |
+------+------+-------+---------+----+----+------+------+----+----+------+------+
我想得到这个输出:
+------+------+-------+---------+-----+-----+-------+------+-----+------+------+------+
| MNRs | GNRs | MSNRs |
+------+------+-------+---------+-----+-----+-------+------+-----+------+------+------+
| N1 | N2 | NR_i | NR_f | N1 | N2 | NR_i | NR_f | N1 | N2 | NR_i | NR_f |
+------+------+-------+---------+-----+-----+-------+------+-----+------+------+------+
| 393 | 720 | 203 | 49994 | 649 | 111 | 55400 | 877 | 748 | 5624 | 8746 | 7773 |
+------+------+-------+---------+-----+-----+-------+------+-----+------+------+------+
| 687 | 345 | 55005 | 1229996 | | | | | 124 | 54 | 8847 | 5526 |
+------+------+-------+---------+-----+-----+-------+------+-----+------+------+------+
谢谢你的帮助。