我有以下代码(xml 和 xslt),我想用 2 个条件计算一些 xml 元素。
XML代码:
<home>
<place Value='place1'>
<property Name="Type" Value="house" />
<property Name="Context" Value="roof" />
<property Name="Color" Value="blue" />
</place>
<place Value='place2'>
<property Name="Type" Value="house" />
<property Name="Context" Value="kitchen" />
<property Name="Color" Value="red" />
</place>
<place Value='>
<property Name="Type" Value="house" />
<property Name="Context" Value="floor" />
<property Name="Color" Value="black" />
</place>
<place Value='place4'>
<property Name="Type" Value="house" />
<property Name="Context" Value="kitchen" />
<property Name="Color" Value="black" />
</place>
<place Value='place5'>
<property Name="Type" Value="apartment" />
<property Name="Context" Value="roof" />
<property Name="Color" Value="blue" />
</place>
<place Value='place6'>
<property Name="Type" Value="apartment" />
<property Name="Context" Value="kitchen" />
<property Name="Color" Value="red" />
</place>
</home>
xslt代码:
<html>
<body>
<table border="1" cellspacing="0" cellpadding="3">
<tr>
<td>Place</td>
<td>Type</td>
<td>Context</td>
<td>Color</td>
</tr>
<xsl:for-each select="place">
<tr>
<td><xsl:value-of select="@Value" /></td>
<td><xsl:value-of select="property[@Name='Type']/@Value" /></td>
<td><xsl:value-of select="property[@Name='Context']/@Value" /></td>
<td><xsl:value-of select="property[@Name='Color']/@Value" /></td>
</tr>
</xsl:for-each>
</table>
<table>
<tr>
<td>
Number of house:
</td>
<td>
<xsl:value-of select="count(place/property[@Name='Type' and @Value='house'])"/>
</td>
</tr>
<tr>
<td>
Number of kitchen:
</td>
<td>
<xsl:value-of select="count(place/property[@Name='Context' and @Value='kitchen'])"/>
</td>
</tr>
<tr>
<td>
Number of house with kitchen:
</td>
<td>
<xsl:value-of select="count(place/property[@Name='Type' and @Value='house'][@Name='Context' and @Value='kitchen'])"/>
</td>
</tr>
</table>
</body>
</html>
前两个计数工作正常(这些计数只有一个条件),但第三个计数不起作用,因为有两个条件。任何建议如何使它工作?谢谢。