我有以下XML代码,我正在尝试使用xlst进行转换:
<setting>
<type>house</type>
<context>roof</context>
<value>blue</value>
</setting>
<setting>
<type>house</type>
<context>kitchen</context>
<value>red</value>
</setting>
<setting>
<type>house</type>
<context>floor</context>
<value>black</value>
</setting>
<setting>
<type>apartment</type>
<context>roof</context>
<value>red</value>
</setting>
我希望能够计算设置类型为“公寓”的对象是否有“上下文-楼层”信息。
我尝试使用以下方法进行计算:
<xsl:if test="count(setting[type='apartment'] and setting[context='floor']) < 1">
<!-- do what ever !-->
</xsl:if>
但似乎没有生效。我遇到了一个异常,说尝试将数字转换为布尔值?有什么建议吗?
更新: 我发现我可以使用:
<xsl:if test="count(setting[type='apartment' and context='floor']) < 1">