使用模板将输入XML转换为输出XML

时间:2015-12-11 21:49:36

标签: xml xslt xpath xslt-2.0

我有一个输入XML,我试图将其转换为更结构化的XML输出。以下是构建数据的几个条件 -

1.如果Report_Entry节点没有Employee_ID子元素,则丢弃整个Report_Entry节点。

2.如果Employee_ID节点存在,则将所有Report_Entry个节点合并为Employee_ID个值。每个Report_Entry节点都将包含Child或Spouse的详细信息。这是基于Relationship节点值确定的。如果Relationship是Spouse,则添加新的子节点Spouse并插入依赖详细信息(名称,SSN,DoB和COBRA详细信息)。如果Relationship是Child,则添加一个新的Dependent节点并将相关详细信息插入其中。

<?xml version='1.0' encoding='UTF-8'?>
<wd:Report_Data xmlns:wd="urn:com.workday.report/DNU_CR_Dependents_COBRA_Records">
    <wd:Report_Entry>
        <wd:Dependent_Name></wd:Dependent_Name>
        <wd:Dependent_COBRA_Records_within_Range>
            <wd:Dependent_COBRA_Eligible_Date>2015-10-11</wd:Dependent_COBRA_Eligible_Date>
            <wd:Dependent_Qualifying_Event_Date>2015-10-10</wd:Dependent_Qualifying_Event_Date>
            <wd:Dependent_Eligibility_Reason>Spouse - Divorce or legal separation of the covered employee</wd:Dependent_Eligibility_Reason>
            <wd:Dependent_Benefit_Plan>Dental-US - Delta Dental PPO BREG</wd:Dependent_Benefit_Plan>
        </wd:Dependent_COBRA_Records_within_Range>
        <wd:Dependent_COBRA_Records_within_Range>
            <wd:Dependent_COBRA_Eligible_Date>2015-10-13</wd:Dependent_COBRA_Eligible_Date>
            <wd:Dependent_Qualifying_Event_Date>2015-10-11</wd:Dependent_Qualifying_Event_Date>
            <wd:Dependent_Eligibility_Reason>Spouse - Divorce or legal separation of the covered employee</wd:Dependent_Eligibility_Reason>
            <wd:Dependent_Benefit_Plan>Medical-US - Local 32</wd:Dependent_Benefit_Plan>
        </wd:Dependent_COBRA_Records_within_Range>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Employee_ID>1003413</wd:Employee_ID>
        <wd:Worker_Name>Amy Bush</wd:Worker_Name>
        <wd:Dependent_Name>Matthew Bush</wd:Dependent_Name>
        <wd:Dependent_First_Name>Matthew</wd:Dependent_First_Name>
        <wd:Dependent_Last_Name>Bush</wd:Dependent_Last_Name>
        <wd:Dependent_Date_of_Birth>1970-12-07</wd:Dependent_Date_of_Birth>
        <wd:Relationship>Spouse</wd:Relationship>
        <wd:Dependent_COBRA_Records_within_Range>
            <wd:Dependent_COBRA_Eligible_Date>2015-10-02</wd:Dependent_COBRA_Eligible_Date>
            <wd:Dependent_Qualifying_Event_Date>2015-10-01</wd:Dependent_Qualifying_Event_Date>
            <wd:Dependent_Eligibility_Reason>Spouse - Divorce or legal separation of the covered employee</wd:Dependent_Eligibility_Reason>
            <wd:Dependent_Benefit_Plan>Dental-US - MetLife Dental PPO Hawaii</wd:Dependent_Benefit_Plan>
        </wd:Dependent_COBRA_Records_within_Range>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Employee_ID>1003413</wd:Employee_ID>
        <wd:Worker_Name>Amy Bush</wd:Worker_Name>
        <wd:Dependent_Name>Katherine Bush</wd:Dependent_Name>
        <wd:Dependent_First_Name>Katherine</wd:Dependent_First_Name>
        <wd:Dependent_Last_Name>Bush</wd:Dependent_Last_Name>
        <wd:Dependent_Date_of_Birth>1999-12-07</wd:Dependent_Date_of_Birth>
        <wd:Dependent_COBRA_Records_within_Range>
            <wd:Dependent_COBRA_Eligible_Date>2015-10-02</wd:Dependent_COBRA_Eligible_Date>
            <wd:Dependent_Qualifying_Event_Date>2015-10-01</wd:Dependent_Qualifying_Event_Date>
            <wd:Dependent_Eligibility_Reason>Dependent Children - Loss of dependent child status under the plan rules</wd:Dependent_Eligibility_Reason>
            <wd:Dependent_Benefit_Plan>Dental-US - MetLife Dental PPO Hawaii</wd:Dependent_Benefit_Plan>
        </wd:Dependent_COBRA_Records_within_Range>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Employee_ID>2001679</wd:Employee_ID>
        <wd:Worker_Name>Phuong-Thao Li (On Leave)</wd:Worker_Name>
        <wd:Dependent_Name>Audrie Li</wd:Dependent_Name>
        <wd:Dependent_First_Name>Audrie</wd:Dependent_First_Name>
        <wd:Dependent_Last_Name>Li</wd:Dependent_Last_Name>
        <wd:Dependent_Date_of_Birth>2011-10-19</wd:Dependent_Date_of_Birth>
        <wd:Relationship>Child</wd:Relationship>
        <wd:Dependent_COBRA_Records_within_Range>
            <wd:Dependent_COBRA_Eligible_Date>2015-11-03</wd:Dependent_COBRA_Eligible_Date>
            <wd:Dependent_Qualifying_Event_Date>2015-11-01</wd:Dependent_Qualifying_Event_Date>
            <wd:Dependent_Eligibility_Reason>Dependent Children - Loss of dependent child status under the plan rules</wd:Dependent_Eligibility_Reason>
            <wd:Dependent_Benefit_Plan>Dental-US - MetLife Dental PPO Hawaii</wd:Dependent_Benefit_Plan>
        </wd:Dependent_COBRA_Records_within_Range>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Employee_ID>2001679</wd:Employee_ID>
        <wd:Worker_Name>Phuong-Thao Li (On Leave)</wd:Worker_Name>
        <wd:Dependent_Name>Colton Li</wd:Dependent_Name>
        <wd:Dependent_First_Name>Colton</wd:Dependent_First_Name>
        <wd:Dependent_Last_Name>Li</wd:Dependent_Last_Name>
        <wd:Dependent_Date_of_Birth>2009-10-29</wd:Dependent_Date_of_Birth>
        <wd:Relationship>Child</wd:Relationship>
        <wd:Dependent_COBRA_Records_within_Range>
            <wd:Dependent_COBRA_Eligible_Date>2015-10-20</wd:Dependent_COBRA_Eligible_Date>
            <wd:Dependent_Qualifying_Event_Date>2015-10-10</wd:Dependent_Qualifying_Event_Date>
            <wd:Dependent_Eligibility_Reason>Employee - Leave of Absence (LTD)</wd:Dependent_Eligibility_Reason>
            <wd:Dependent_Benefit_Plan>Dental-US - MetLife Dental PPO Hawaii</wd:Dependent_Benefit_Plan>
        </wd:Dependent_COBRA_Records_within_Range>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Employee_ID>2001679</wd:Employee_ID>
        <wd:Worker_Name>Phuong-Thao Li (On Leave)</wd:Worker_Name>
        <wd:Dependent_Name>Kaelyn Li</wd:Dependent_Name>
        <wd:Dependent_First_Name>Kaelyn</wd:Dependent_First_Name>
        <wd:Dependent_Last_Name>Li</wd:Dependent_Last_Name>
        <wd:Dependent_Date_of_Birth>2004-09-25</wd:Dependent_Date_of_Birth>
        <wd:Relationship>Child</wd:Relationship>
        <wd:Dependent_COBRA_Records_within_Range>
            <wd:Dependent_COBRA_Eligible_Date>2015-11-01</wd:Dependent_COBRA_Eligible_Date>
            <wd:Dependent_Qualifying_Event_Date>2015-10-20</wd:Dependent_Qualifying_Event_Date>
            <wd:Dependent_Eligibility_Reason>Dependent Children - Loss of dependent child status under the plan rules</wd:Dependent_Eligibility_Reason>
            <wd:Dependent_Benefit_Plan>Dental-US - MetLife Dental PPO Hawaii</wd:Dependent_Benefit_Plan>
        </wd:Dependent_COBRA_Records_within_Range>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Employee_ID>2001679</wd:Employee_ID>
        <wd:Worker_Name>Phuong-Thao Li (On Leave)</wd:Worker_Name>
        <wd:Dependent_Name>Eliza Li</wd:Dependent_Name>
        <wd:Dependent_First_Name>Eliza</wd:Dependent_First_Name>
        <wd:Dependent_Last_Name>Li</wd:Dependent_Last_Name>
        <wd:Dependent_Date_of_Birth>1988-11-01</wd:Dependent_Date_of_Birth>
        <wd:Relationship>Spouse</wd:Relationship>
        <wd:Dependent_COBRA_Records_within_Range>
            <wd:Dependent_COBRA_Eligible_Date>2015-09-06</wd:Dependent_COBRA_Eligible_Date>
            <wd:Dependent_Qualifying_Event_Date>2015-09-03</wd:Dependent_Qualifying_Event_Date>
            <wd:Dependent_Eligibility_Reason>Employee - Leave of Absence (LTD)</wd:Dependent_Eligibility_Reason>
            <wd:Dependent_Benefit_Plan>Medical-US - Local 501 HMO</wd:Dependent_Benefit_Plan>
        </wd:Dependent_COBRA_Records_within_Range>
        <wd:Dependent_COBRA_Records_within_Range>
            <wd:Dependent_COBRA_Eligible_Date>2015-09-06</wd:Dependent_COBRA_Eligible_Date>
            <wd:Dependent_Qualifying_Event_Date>2015-09-01</wd:Dependent_Qualifying_Event_Date>
            <wd:Dependent_Eligibility_Reason>Spouse - Divorce or legal separation of the covered employee</wd:Dependent_Eligibility_Reason>
            <wd:Dependent_Benefit_Plan>Dental-US - MetLife Dental PPO Hawaii</wd:Dependent_Benefit_Plan>
        </wd:Dependent_COBRA_Records_within_Range>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Employee_ID>2001679</wd:Employee_ID>
        <wd:Worker_Name>Phuong-Thao Li (On Leave)</wd:Worker_Name>
        <wd:Dependent_Name>Andria Li</wd:Dependent_Name>
        <wd:Dependent_First_Name>Andria</wd:Dependent_First_Name>
        <wd:Dependent_Last_Name>Li</wd:Dependent_Last_Name>
        <wd:Dependent_Date_of_Birth>2000-11-01</wd:Dependent_Date_of_Birth>
        <wd:Relationship>Child</wd:Relationship>
        <wd:Dependent_COBRA_Records_within_Range>
            <wd:Dependent_COBRA_Eligible_Date>2015-10-05</wd:Dependent_COBRA_Eligible_Date>
            <wd:Dependent_Qualifying_Event_Date>2015-10-02</wd:Dependent_Qualifying_Event_Date>
            <wd:Dependent_Eligibility_Reason>Dependent Children - Loss of dependent child status under the plan rules</wd:Dependent_Eligibility_Reason>
            <wd:Dependent_Benefit_Plan>Dental-US - MetLife Dental PPO Hawaii</wd:Dependent_Benefit_Plan>
        </wd:Dependent_COBRA_Records_within_Range>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Employee_ID>9100637</wd:Employee_ID>
        <wd:Worker_Name>Cheri Holtzworth (Retired - Active)</wd:Worker_Name>
        <wd:Dependent_Name>Annie Holtzworth</wd:Dependent_Name>
        <wd:Dependent_First_Name>Annie</wd:Dependent_First_Name>
        <wd:Dependent_Last_Name>Holtzworth</wd:Dependent_Last_Name>
        <wd:Dependent_Date_of_Birth>1989-10-04</wd:Dependent_Date_of_Birth>
        <wd:Relationship>Spouse</wd:Relationship>
        <wd:Dependent_COBRA_Records_within_Range>
            <wd:Dependent_COBRA_Eligible_Date>2015-10-29</wd:Dependent_COBRA_Eligible_Date>
            <wd:Dependent_Qualifying_Event_Date>2015-10-28</wd:Dependent_Qualifying_Event_Date>
            <wd:Dependent_Eligibility_Reason>Employee - Death of Employee</wd:Dependent_Eligibility_Reason>
            <wd:Dependent_Benefit_Plan>Healthcare FSA - Empire FSA</wd:Dependent_Benefit_Plan>
        </wd:Dependent_COBRA_Records_within_Range>
    </wd:Report_Entry>
</wd:Report_Data>

我想要这种格式的输出 -

<?xml version='1.0' encoding='UTF-8'?>
<wd:Report_Data xmlns:wd="urn:com.workday.report/DNU_CR_Dependents_COBRA_Records">
    <wd:Report_Entry>
        <wd:Employee_ID>1003413</wd:Employee_ID>
        <wd:Spouse>
            <wd:Worker_Name>Amy Bush</wd:Worker_Name>
            <wd:Dependent_Name>Matthew Bush</wd:Dependent_Name>
            <wd:Dependent_First_Name>Matthew</wd:Dependent_First_Name>
            <wd:Dependent_Last_Name>Bush</wd:Dependent_Last_Name>
            <wd:Dependent_Date_of_Birth>1970-12-07</wd:Dependent_Date_of_Birth>
            <wd:Dependent_COBRA_Records_within_Range>
                <wd:Dependent_COBRA_Eligible_Date>2015-10-02</wd:Dependent_COBRA_Eligible_Date>
                <wd:Dependent_Qualifying_Event_Date>2015-10-01</wd:Dependent_Qualifying_Event_Date>
                <wd:Dependent_Eligibility_Reason>Spouse - Divorce or legal separation of the covered
                    employee</wd:Dependent_Eligibility_Reason>
                <wd:Dependent_Benefit_Plan>Dental-US - MetLife Dental PPO
                    Hawaii</wd:Dependent_Benefit_Plan>
            </wd:Dependent_COBRA_Records_within_Range>
        </wd:Spouse>
        <wd:Dependent>
            <wd:Worker_Name>Amy Bush</wd:Worker_Name>
            <wd:Dependent_Name>Katherine Bush</wd:Dependent_Name>
            <wd:Dependent_First_Name>Katherine</wd:Dependent_First_Name>
            <wd:Dependent_Last_Name>Bush</wd:Dependent_Last_Name>
            <wd:Dependent_Date_of_Birth>1999-12-07</wd:Dependent_Date_of_Birth>
            <wd:Dependent_COBRA_Records_within_Range>
                <wd:Dependent_COBRA_Eligible_Date>2015-10-02</wd:Dependent_COBRA_Eligible_Date>
                <wd:Dependent_Qualifying_Event_Date>2015-10-01</wd:Dependent_Qualifying_Event_Date>
                <wd:Dependent_Eligibility_Reason>Dependent Children - Loss of dependent child status
                    under the plan rules</wd:Dependent_Eligibility_Reason>
                <wd:Dependent_Benefit_Plan>Dental-US - MetLife Dental PPO
                    Hawaii</wd:Dependent_Benefit_Plan>
            </wd:Dependent_COBRA_Records_within_Range>
        </wd:Dependent>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Employee_ID>2001679</wd:Employee_ID>
        <wd:Dependent>
            <wd:Worker_Name>Phuong-Thao Li (On Leave)</wd:Worker_Name>
            <wd:Dependent_Name>Audrie Li</wd:Dependent_Name>
            <wd:Dependent_First_Name>Audrie</wd:Dependent_First_Name>
            <wd:Dependent_Last_Name>Li</wd:Dependent_Last_Name>
            <wd:Dependent_Date_of_Birth>2011-10-19</wd:Dependent_Date_of_Birth>
            <wd:Dependent_COBRA_Records_within_Range>
                <wd:Dependent_COBRA_Eligible_Date>2015-11-03</wd:Dependent_COBRA_Eligible_Date>
                <wd:Dependent_Qualifying_Event_Date>2015-11-01</wd:Dependent_Qualifying_Event_Date>
                <wd:Dependent_Eligibility_Reason>Dependent Children - Loss of dependent child status
                    under the plan rules</wd:Dependent_Eligibility_Reason>
                <wd:Dependent_Benefit_Plan>Dental-US - MetLife Dental PPO
                    Hawaii</wd:Dependent_Benefit_Plan>
            </wd:Dependent_COBRA_Records_within_Range>
        </wd:Dependent>
        <wd:Dependent>
            <wd:Worker_Name>Phuong-Thao Li (On Leave)</wd:Worker_Name>
            <wd:Dependent_Name>Colton Li</wd:Dependent_Name>
            <wd:Dependent_First_Name>Colton</wd:Dependent_First_Name>
            <wd:Dependent_Last_Name>Li</wd:Dependent_Last_Name>
            <wd:Dependent_COBRA_Records_within_Range>
                <wd:Dependent_COBRA_Eligible_Date>2015-10-20</wd:Dependent_COBRA_Eligible_Date>
                <wd:Dependent_Qualifying_Event_Date>2015-10-10</wd:Dependent_Qualifying_Event_Date>
                <wd:Dependent_Eligibility_Reason>Employee - Leave of Absence
                    (LTD)</wd:Dependent_Eligibility_Reason>
                <wd:Dependent_Benefit_Plan>Dental-US - MetLife Dental PPO
                    Hawaii</wd:Dependent_Benefit_Plan>
            </wd:Dependent_COBRA_Records_within_Range>
        </wd:Dependent>
        <wd:Dependent>
            <wd:Worker_Name>Phuong-Thao Li (On Leave)</wd:Worker_Name>
            <wd:Dependent_Name>Kaelyn Li</wd:Dependent_Name>
            <wd:Dependent_First_Name>Kaelyn</wd:Dependent_First_Name>
            <wd:Dependent_Last_Name>Li</wd:Dependent_Last_Name>
            <wd:Dependent_Date_of_Birth>2004-09-25</wd:Dependent_Date_of_Birth>
            <wd:Dependent_COBRA_Records_within_Range>
                <wd:Dependent_COBRA_Eligible_Date>2015-11-01</wd:Dependent_COBRA_Eligible_Date>
                <wd:Dependent_Qualifying_Event_Date>2015-10-20</wd:Dependent_Qualifying_Event_Date>
                <wd:Dependent_Eligibility_Reason>Dependent Children - Loss of dependent child status
                    under the plan rules</wd:Dependent_Eligibility_Reason>
                <wd:Dependent_Benefit_Plan>Dental-US - MetLife Dental PPO
                    Hawaii</wd:Dependent_Benefit_Plan>
            </wd:Dependent_COBRA_Records_within_Range>
        </wd:Dependent>
        <wd:Spouse>
            <wd:Worker_Name>Phuong-Thao Li (On Leave)</wd:Worker_Name>
            <wd:Dependent_Name>Eliza Li</wd:Dependent_Name>
            <wd:Dependent_First_Name>Eliza</wd:Dependent_First_Name>
            <wd:Dependent_Last_Name>Li</wd:Dependent_Last_Name>
            <wd:Dependent_Date_of_Birth>1988-11-01</wd:Dependent_Date_of_Birth>
            <wd:Dependent_COBRA_Records_within_Range>
                <wd:Dependent_COBRA_Eligible_Date>2015-09-06</wd:Dependent_COBRA_Eligible_Date>
                <wd:Dependent_Qualifying_Event_Date>2015-09-03</wd:Dependent_Qualifying_Event_Date>
                <wd:Dependent_Eligibility_Reason>Employee - Leave of Absence
                    (LTD)</wd:Dependent_Eligibility_Reason>
                <wd:Dependent_Benefit_Plan>Medical-US - Local 501 HMO</wd:Dependent_Benefit_Plan>
            </wd:Dependent_COBRA_Records_within_Range>
            <wd:Dependent_COBRA_Records_within_Range>
                <wd:Dependent_COBRA_Eligible_Date>2015-09-06</wd:Dependent_COBRA_Eligible_Date>
                <wd:Dependent_Qualifying_Event_Date>2015-09-01</wd:Dependent_Qualifying_Event_Date>
                <wd:Dependent_Eligibility_Reason>Spouse - Divorce or legal separation of the covered
                    employee</wd:Dependent_Eligibility_Reason>
                <wd:Dependent_Benefit_Plan>Dental-US - MetLife Dental PPO
                    Hawaii</wd:Dependent_Benefit_Plan>
            </wd:Dependent_COBRA_Records_within_Range>
        </wd:Spouse>
        <wd:Dependent>
            <wd:Worker_Name>Phuong-Thao Li (On Leave)</wd:Worker_Name>
            <wd:Dependent_Name>Andria Li</wd:Dependent_Name>
            <wd:Dependent_First_Name>Andria</wd:Dependent_First_Name>
            <wd:Dependent_Last_Name>Li</wd:Dependent_Last_Name>
            <wd:Dependent_Date_of_Birth>2000-11-01</wd:Dependent_Date_of_Birth>
            <wd:Dependent_COBRA_Records_within_Range>
                <wd:Dependent_COBRA_Eligible_Date>2015-10-05</wd:Dependent_COBRA_Eligible_Date>
                <wd:Dependent_Qualifying_Event_Date>2015-10-02</wd:Dependent_Qualifying_Event_Date>
                <wd:Dependent_Eligibility_Reason>Dependent Children - Loss of dependent child status
                    under the plan rules</wd:Dependent_Eligibility_Reason>
                <wd:Dependent_Benefit_Plan>Dental-US - MetLife Dental PPO
                    Hawaii</wd:Dependent_Benefit_Plan>
            </wd:Dependent_COBRA_Records_within_Range>
        </wd:Dependent>
    </wd:Report_Entry>
    <wd:Report_Entry>
        <wd:Employee_ID>9100637</wd:Employee_ID>
        <wd:Spouse>
            <wd:Worker_Name>Cheri Holtzworth (Retired - Active)</wd:Worker_Name>
            <wd:Dependent_Name>Annie Holtzworth</wd:Dependent_Name>
            <wd:Dependent_First_Name>Annie</wd:Dependent_First_Name>
            <wd:Dependent_Last_Name>Holtzworth</wd:Dependent_Last_Name>
            <wd:Dependent_Date_of_Birth>1989-10-04</wd:Dependent_Date_of_Birth>
            <wd:Dependent_COBRA_Records_within_Range>
                <wd:Dependent_COBRA_Eligible_Date>2015-10-29</wd:Dependent_COBRA_Eligible_Date>
                <wd:Dependent_Qualifying_Event_Date>2015-10-28</wd:Dependent_Qualifying_Event_Date>
                <wd:Dependent_Eligibility_Reason>Employee - Death of
                    Employee</wd:Dependent_Eligibility_Reason>
                <wd:Dependent_Benefit_Plan>Healthcare FSA - Empire FSA</wd:Dependent_Benefit_Plan>
            </wd:Dependent_COBRA_Records_within_Range>
        </wd:Spouse>
    </wd:Report_Entry>
</wd:Report_Data>

我试图弄清楚如何使用模板并创建了一个XSLT,但却无法编写正确的逻辑来获得所需的输出 -

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:wd="urn:com.workday/DNU_CR_Dependents_COBRA_Records">
    <xsl:output method="xml" encoding="utf-8" indent="yes"/>
    <xsl:template match="wd:Report_Data">
        <wd:Report_Data xmlns:wd="urn:com.workday.report/DNU_CR_Dependents_COBRA_Records"><wd:Report_Entry><xsl:apply-templates select="wd:Report_Entry"/>
            </wd:Report_Entry>
        </wd:Report_Data>
    </xsl:template>

    <xsl:template match="wd:Report_Entry">
        <wd:Dependent><xsl:apply-templates select="wd:Worker_Name"/>
            <xsl:apply-templates select="wd:Dependent_Name"/>
            <xsl:apply-templates select="wd:Dependent_First_Name"/>
            <xsl:apply-templates select="wd:Dependent_Last_Name"/>
            <xsl:apply-templates select="wd:Dependent_Date_of_Birth"/>
            <xsl:apply-templates select="wd:Dependent_COBRA_Records_within_Range"/>
        </wd:Dependent>
    </xsl:template>

    <xsl:template match="wd:Dependent_COBRA_Records_within_Range">
        <wd:Dependent_COBRA_Records_within_Range><xsl:apply-templates select="wd:Dependent_COBRA_Eligible_Date"/>
            <xsl:apply-templates select="wd:Dependent_Qualifying_Event_Date"/>
        </wd:Dependent_COBRA_Records_within_Range>
    </xsl:template>

    <xsl:template match="wd:Report_Entry">
        <wd:Report_Entry><xsl:apply-templates select="wd:Employee_ID"/>
            <wd:Spouse><xsl:apply-templates select="wd:Worker_Name"/>
                <xsl:apply-templates select="wd:Dependent_Name"/>
                <xsl:apply-templates select="wd:Dependent_First_Name"/>
                <xsl:apply-templates select="wd:Dependent_Last_Name"/>
                <xsl:apply-templates select="wd:Dependent_Date_of_Birth"/>
                <xsl:apply-templates select="wd:Dependent_COBRA_Records_within_Range"/>
            </wd:Spouse>
        </wd:Report_Entry>
    </xsl:template>

    <xsl:template match="wd:Dependent_Qualifying_Event_Date">
        <wd:Dependent_Qualifying_Event_Date><xsl:value-of select="."/></wd:Dependent_Qualifying_Event_Date>
    </xsl:template>

    <xsl:template match="wd:Employee_ID">
        <wd:Employee_ID><xsl:value-of select="."/></wd:Employee_ID>
    </xsl:template>

    <xsl:template match="wd:Worker_Name">
        <wd:Worker_Name><xsl:value-of select="."/></wd:Worker_Name>
    </xsl:template>

    <xsl:template match="wd:Dependent_Name">
        <wd:Dependent_Name><xsl:value-of select="."/></wd:Dependent_Name>
    </xsl:template>

    <xsl:template match="wd:Dependent_First_Name">
        <wd:Dependent_First_Name><xsl:value-of select="."/></wd:Dependent_First_Name>
    </xsl:template>

    <xsl:template match="wd:Dependent_Last_Name">
        <wd:Dependent_Last_Name><xsl:value-of select="."/></wd:Dependent_Last_Name>
    </xsl:template>

    <xsl:template match="wd:Dependent_Date_of_Birth">
        <wd:Dependent_Date_of_Birth><xsl:value-of select="."/></wd:Dependent_Date_of_Birth>
    </xsl:template>

    <xsl:template match="wd:Dependent_COBRA_Eligible_Date">
        <wd:Dependent_COBRA_Eligible_Date><xsl:value-of select="."/></wd:Dependent_COBRA_Eligible_Date>
    </xsl:template>

    <xsl:template match="wd:Dependent_COBRA_Eligible_Date">
        <wd:Dependent_Qualifying_Event_Date><xsl:value-of select="."/></wd:Dependent_Qualifying_Event_Date>
    </xsl:template>

    <xsl:template match="wd:Dependent_Qualifying_Event_Date">
        <wd:Dependent_COBRA_Eligible_Date><xsl:value-of select="."/></wd:Dependent_COBRA_Eligible_Date>
    </xsl:template>

    <xsl:template match="wd:Dependent_Benefit_Plan">
        <wd:Dependent_Benefit_Plan><xsl:value-of select="."/></wd:Dependent_Benefit_Plan>
    </xsl:template>

</xsl:stylesheet>

1 个答案:

答案 0 :(得分:0)

  

1.如果Report_Entry节点没有Employee_ID子元素,则丢弃整个Report_Entry节点。

     

2.如果Employee_ID节点存在,则将所有Report_Entry节点合并为具有相同的Employee_ID值。每个Report_Entry节点都有详细信息   儿童或配偶。这是基于关系确定的   节点值。如果Relationship是Spouse,则添加一个新的子节点Spouse   并插入依赖详细信息(名称,SSN,DoB和COBRA详细信息)。   如果Relationship是Child,则添加一个新的Dependent节点并插入   依赖细节。

AFAICT,所有这些要求都可以通过以下方式满足:

XSLT 2.0

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wd="urn:com.workday.report/DNU_CR_Dependents_COBRA_Records">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="/wd:Report_Data">
    <xsl:copy>
        <xsl:for-each-group select="wd:Report_Entry[wd:Employee_ID]" group-by="wd:Employee_ID">
            <wd:Report_Entry>
                <xsl:copy-of select="wd:Employee_ID"/>
                <xsl:apply-templates select="current-group()"/>
             </wd:Report_Entry>
        </xsl:for-each-group>
    </xsl:copy>
</xsl:template>

<xsl:template match="wd:Report_Entry">
    <xsl:element name="wd:{if (wd:Relationship='Spouse') then 'Spouse' else 'Dependent'}">
        <xsl:apply-templates select="wd:Worker_Name | wd:Dependent_Name | wd:Dependent_First_Name | wd:Dependent_Last_Name | wd:Dependent_Date_of_Birth | wd:Dependent_COBRA_Records_within_Range"/>
    </xsl:element>
</xsl:template>

</xsl:stylesheet>

注意

  

每个Report_Entry节点都会有Child或Spouse的详细信息。

在你的例子中,凯瑟琳布什既不是孩子也不是配偶 - 但你将她列为依赖者。我认为这意味着任何 Report_Entry不是配偶是依赖的。