基于条件的 XSL 计数
XSL count based on conditions
我有 XML 类似于以下的数据:
<?xml version="1.0" encoding="utf-8"?>
<Database>
<ResultsStore>
<Result Type="A">
<Info Value="3" />
</Result>
<Result Type="B">
<Info Value="0" />
</Result>
<Result Type="C">
<Info Value="1" />
</Result>
</ResultsStore>
<ResultsStore>
<Result Type="A">
<Info Value="3" />
</Result>
<Result Type="B">
<Info Value="0" />
</Result>
<Result Type="C">
<Info Value="0" />
</Result>
</ResultsStore>
<ResultsStore>
<Result Type="A">
<Info Value="3" />
</Result>
<Result Type="B">
<Info Value="1" />
</Result>
<Result Type="C">
<Info Value="1" />
</Result>
</ResultsStore>
<!-- etc. -->
</Database>
我需要计算具有非零信息值的结果 B 或结果 C 的 ResultsStores 的数量。在上面的代码示例中,三个 ResultsStores 的计数应为 2。
我写了下面的代码,但它给出了不正确的值 3,因为它不仅计算 B 或 C 一次:
<xsl:variable name="results_stores_count">
<xsl:value-of select="count(Database/ResultsStore/Result[@Type='A' or @Type='B']/Info[not(@Value=0)]) />
</xsl:variable>
如有任何帮助或解决方法,我们将不胜感激。
count the number of ResultsStores that have either Result B or Result C with a non-zero Info Value.
如果要计算 ResultsStores,则不要计算 Results。另外,如果要计算 B 和 C 类型,则不要计算 A 和 B 类型。
尝试:
<xsl:value-of select="count(Database/ResultsStore[Result[@Type='B']/Info/@Value!=0 or Result[@Type='C']/Info/@Value!=0]) "/>
我有 XML 类似于以下的数据:
<?xml version="1.0" encoding="utf-8"?>
<Database>
<ResultsStore>
<Result Type="A">
<Info Value="3" />
</Result>
<Result Type="B">
<Info Value="0" />
</Result>
<Result Type="C">
<Info Value="1" />
</Result>
</ResultsStore>
<ResultsStore>
<Result Type="A">
<Info Value="3" />
</Result>
<Result Type="B">
<Info Value="0" />
</Result>
<Result Type="C">
<Info Value="0" />
</Result>
</ResultsStore>
<ResultsStore>
<Result Type="A">
<Info Value="3" />
</Result>
<Result Type="B">
<Info Value="1" />
</Result>
<Result Type="C">
<Info Value="1" />
</Result>
</ResultsStore>
<!-- etc. -->
</Database>
我需要计算具有非零信息值的结果 B 或结果 C 的 ResultsStores 的数量。在上面的代码示例中,三个 ResultsStores 的计数应为 2。
我写了下面的代码,但它给出了不正确的值 3,因为它不仅计算 B 或 C 一次:
<xsl:variable name="results_stores_count">
<xsl:value-of select="count(Database/ResultsStore/Result[@Type='A' or @Type='B']/Info[not(@Value=0)]) />
</xsl:variable>
如有任何帮助或解决方法,我们将不胜感激。
count the number of ResultsStores that have either Result B or Result C with a non-zero Info Value.
如果要计算 ResultsStores,则不要计算 Results。另外,如果要计算 B 和 C 类型,则不要计算 A 和 B 类型。
尝试:
<xsl:value-of select="count(Database/ResultsStore[Result[@Type='B']/Info/@Value!=0 or Result[@Type='C']/Info/@Value!=0]) "/>