XSLT标识转换-基于子值复制父级,而不复制其他子级



我有以下xml:

<?xml version="1.0" encoding="utf-8"?>
<peci:Worker_Effective_Stack_Aggregate xmlns:peci="urn:com.workday/peci">
<peci:Workers_Effective_Stack xmlns:peci="urn:com.workday/peci">
<peci:Summary>
<peci:Integration_Event>6d374dcbe3a81024090d271cab840000</peci:Integration_Event>
</peci:Summary>
<peci:Worker>
<peci:Worker_Summary>
<peci:Employee_ID>328556</peci:Employee_ID>
</peci:Worker_Summary>
<peci:Effective_Change peci:Sequence="0">
<peci:Derived_Event_Code>HIR</peci:Derived_Event_Code>
<peci:Effective_Moment>2022-07-27T00:00:00.000-07:00</peci:Effective_Moment>
<peci:Entry_Moment>2022-07-27T03:24:11.531-07:00</peci:Entry_Moment>              
</peci:Effective_Change>
<peci:Effective_Change peci:Sequence="1">
<peci:Derived_Event_Code>DTA</peci:Derived_Event_Code>
<peci:Effective_Moment>2022-07-27T03:30:05.861-07:00</peci:Effective_Moment>
<peci:Entry_Moment>2022-07-27T03:30:05.861-07:00</peci:Entry_Moment>
</peci:Effective_Change>
</peci:Worker>
<peci:Worker>
<peci:Worker_Summary>
<peci:Employee_ID>328557</peci:Employee_ID>
</peci:Worker_Summary>
<peci:Effective_Change peci:Sequence="0">
<peci:Derived_Event_Code>HIR</peci:Derived_Event_Code>
<peci:Effective_Moment>2022-07-27T00:00:00.000-07:00</peci:Effective_Moment>
<peci:Entry_Moment>2022-07-27T04:44:30.864-07:00</peci:Entry_Moment>              
</peci:Effective_Change>
</peci:Worker>
<peci:Worker>
<peci:Worker_Summary>
<peci:Employee_ID>1111132</peci:Employee_ID>
</peci:Worker_Summary>
<peci:Effective_Change peci:Sequence="0">
<peci:Derived_Event_Code>DTA</peci:Derived_Event_Code>
<peci:Effective_Moment>2022-07-25T00:00:00.000-07:00</peci:Effective_Moment>
<peci:Entry_Moment>2022-07-25T04:44:30.864-07:00</peci:Entry_Moment>              
</peci:Effective_Change>
</peci:Worker>
</peci:Workers_Effective_Stack>
</peci:Worker_Effective_Stack_Aggregate>

我想得到这样的东西(只有员工参加招聘活动,只有招聘活动(:

<?xml version="1.0" encoding="UTF-8"?>
<peci:Worker_Effective_Stack_Aggregate xmlns:peci="urn:com.workday/peci">
<peci:Workers_Effective_Stack>
<peci:Summary>
<peci:Integration_Event>6d374dcbe3a81024090d271cab840000</peci:Integration_Event>
</peci:Summary>
<peci:Worker>
<peci:Worker_Summary>
<peci:Employee_ID>328556</peci:Employee_ID>
</peci:Worker_Summary>
<peci:Effective_Change peci:Sequence="0">
<peci:Derived_Event_Code>HIR</peci:Derived_Event_Code>
<peci:Effective_Moment>2022-07-27T00:00:00.000-07:00</peci:Effective_Moment>
<peci:Entry_Moment>2022-07-27T03:24:11.531-07:00</peci:Entry_Moment>
</peci:Effective_Change>
</peci:Worker>
<peci:Worker>
<peci:Worker_Summary>
<peci:Employee_ID>328557</peci:Employee_ID>
</peci:Worker_Summary>
<peci:Effective_Change peci:Sequence="0">
<peci:Derived_Event_Code>HIR</peci:Derived_Event_Code>
<peci:Effective_Moment>2022-07-27T00:00:00.000-07:00</peci:Effective_Moment>
<peci:Entry_Moment>2022-07-27T04:44:30.864-07:00</peci:Entry_Moment>
</peci:Effective_Change>
</peci:Worker>
</peci:Workers_Effective_Stack>
</peci:Worker_Effective_Stack_Aggregate>

这是我的代码

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:peci="urn:com.workday/peci">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match='peci:Effective_Change[peci:Derived_Event_Code != "HIR"]'/>

</xsl:stylesheet>

不幸的是,它不会删除没有HIR事件代码(最后一个(的工作程序。我试着添加这个

<xsl:template match="peci:Worker[peci:Effective_Change/peci:Derived_Event_Code!='HIR']"/>

但它删除了第一个工作者(同时还有两个事务(。

提前感谢

Przemek

好的,我需要

<xsl:template match="peci:Worker[not(peci:Effective_Change/peci:Derived_Event_Code='HIR')]"/>

但有人能解释一下原因吗?

相关内容

最新更新