有没有办法识别具有多个条件的 XSLT 中的行数?

Is there a way to identify the count of rows in the XSLT with mutiple conditions?

我正在尝试通过 xsl 从下面的示例 XML 中获取我的输出中的条目数。

背景: 每个员工都有一些家属(子女、配偶),根据员工覆盖范围,我们将在输出文件中填充结果。

如果 'Employee_only' 覆盖,那么我们将不会在输出中有依赖项。 如果 'Family coverage',那么我们将在输出中包含 dependents。

<root xmlns:wd="http://wd.com">        <!-- Added by edit -->
    <wd:Report_Entry>
        <wd:Employee_ID>Empl_001</wd:Employee_ID>
        <wd:Benefits>
            <wd:Coverage>Family</wd:Coverage>
        </wd:Benefits>
        <wd:Dependents>
            <wd:Relationship1>Child</wd:Relationship1>
            <wd:Dep_LastName>Child_A</wd:Dep_LastName>
        </wd:Dependents>
        <wd:Dependents>
            <wd:Relationship1>Spouse</wd:Relationship1>
            <wd:Dep_LastName>Spouse</wd:Dep_LastName>
        </wd:Dependents>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Employee_ID>Empl_002</wd:Employee_ID>
        <wd:Benefits>
            <wd:Coverage>Family</wd:Coverage>
        </wd:Benefits>
        <wd:Dependents>
            <wd:Relationship1>Child</wd:Relationship1>
            <wd:Dep_LastName>Child_A</wd:Dep_LastName>
        </wd:Dependents>
        <wd:Dependents>
            <wd:Relationship1>Child</wd:Relationship1>
            <wd:Dep_LastName>Child_B</wd:Dep_LastName>
        </wd:Dependents>
        <wd:Dependents>
            <wd:Relationship1>Spouse</wd:Relationship1>
            <wd:Dep_LastName>Spouse</wd:Dep_LastName>
        </wd:Dependents>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Employee_ID>Empl_003</wd:Employee_ID>
        <wd:Benefits>
            <wd:Coverage>Employee_Only</wd:Coverage>
        </wd:Benefits>
        <wd:Dependents>
            <wd:Relationship1>Child</wd:Relationship1>
            <wd:Dep_LastName>Child_A</wd:Dep_LastName>
        </wd:Dependents>
        <wd:Dependents>
            <wd:Relationship1>Spouse</wd:Relationship1>
            <wd:Dep_LastName>Spouse</wd:Dep_LastName>
        </wd:Dependents>
    </wd:Report_Entry>
</root>                               <!-- Added by edit -->

-- 输出将如下所示:

Header
Empl_001
001_Child_A
001_Spouse
Empl_002
002_Child_A
002_Child_B
002_Spouse
Empl_003
Trailer -  **8**

此 XML 结果的预期计数将是 8 而不是 10,因为最后一名员工的覆盖范围是 "Employee_only" 而不是 "Family"。

条件:计算员工 + 家属[对于拥有家庭保险的员工]。

我正在使用以下 XSLT 代码:

我需要整理员工 + 家属的总数 [对于覆盖范围为 'Family']

的员工

各位高手,请教一下这种情况下怎么算

您的标题提到 "multiple conditions",但我只看到一个。要计算覆盖范围为 "Family" 的员工的家属,请使用:

<xsl:value-of select="count(//wd:Report_Entry[wd:Benefits/wd:Coverage='Family']/wd:Dependents)"/>

要将 所有 名员工(无条件)包括在计数中,您可以执行以下操作:

<xsl:value-of select="count(//wd:Report_Entry | //wd:Report_Entry[wd:Benefits/wd:Coverage='Family']/wd:Dependents)"/>

试试这个 XPath-1.0 表达式:

count(//wd:Report_Entry) + count(//wd:Report_Entry[wd:Benefits/wd:Coverage ='Family']/wd:Dependents)

其结果为3+5=8.