是否可以让表只显示没有子节点的父节点?我只想在表格中显示AT-2和AT-3项目......
XML:
<root>
<Item type="Acceptance Test">
<jav_acc_id>AT-1</jav_acc_id>
<Relationships>
<Item type="Acceptance Test Requirements">
<related_id>
<Item type="Requirement">
<item_number>REQ-1</item_number>
</Item>
</related_id>
</Item>
</Relationships>
</Item>
<Item type="Acceptance Test">
<jav_acc_id>AT-2</jav_acc_id>
</Item>
<Item type="Acceptance Test">
<jav_acc_id>AT-3</jav_acc_id>
</Item>
</root>
这是我到目前为止所展示的一切 XSLT1.0:
<xsl:template match="/root">
<html>
<body>
<table border="1">
<tr bgcolor="#9acd32">
<th>Acceptance Test</th>
<th>Requirement</th>
</tr>
<tr>
<xsl:for-each select="Item">
<tr>
<td>
<xsl:value-of select="jav_acc_id"/>
</td>
<td>
<xsl:value-of select=".//item_number"/>
<xsl:if test=".//item_number='' or not(.//item_number)">
<xsl:text> </xsl:text>
</xsl:if>
</td>
</tr>
</xsl:for-each>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:1)
您可以使用<Relationships>
测试<xsl:if>
是否缺席:
<xsl:for-each select="Item">
<tr>
<xsl:if test="not(Relationships)">
...
</xsl:if>
</tr>
</xsl:for-each>