【发布时间】:2021-03-15 08:26:58
【问题描述】:
我正在尝试根据字段 start_date 对子节点进行排序。在下面的 XML 节点 <employment_information> 中有两个子节点 <job_information>,start_date 需要升序。
经过大量搜索和尝试,我的排序工作正常,但我遇到的问题是<employment_information> 中的其他字段消失了。节点<job_information> 的顺序正确,但其他字段已消失。
我的 XML:
<queryCompoundEmployeeResponse>
<CompoundEmployee period_start="2020-09-30" period_end="2020-12-03">
<id>347</id>
<type>CompoundEmployee</type>
<swHire>Y</swHire>
<swRehire>N</swRehire>
<swRetire>N</swRetire>
<person>
<action>NO CHANGE</action>
<country_of_birth>NLD</country_of_birth>
<created_by>admin_nm</created_by>
<created_on_timestamp>2018-05-02T14:03:25.000Z</created_on_timestamp>
<person_id>347</person_id>
<person_id_external>10160</person_id_external>
<place_of_birth>aaa</place_of_birth>
<employment_information>
<action>NO CHANGE</action>
<assignment_class>ST</assignment_class>
<created_by>admin_nm</created_by>
<created_on_timestamp>2018-05-02T14:03:25.000Z</created_on_timestamp>
<direct_reports>12</direct_reports>
<employment_id>347</employment_id>
<hiringNotCompleted>false</hiringNotCompleted>
<isContingentWorker>false</isContingentWorker>
<jobNumber>1</jobNumber>
<last_modified_by>aaa</last_modified_by>
<last_modified_on>2019-09-05T10:38:50.000Z</last_modified_on>
<originalStartDate>1992-05-01</originalStartDate>
<serviceDate>1992-05-01</serviceDate>
<start_date>1992-05-01</start_date>
<user_id>10160</user_id>
<job_information>
<action>CHANGE</action>
<shift_factor>0.0</shift_factor>
<shift_rate>0.0</shift_rate>
<standard_hours>38.0</standard_hours>
<start_date>2020-10-10</start_date>
<time_recording_admissibility_code>NL</time_recording_admissibility_code>
<time_recording_profile_code>NL</time_recording_profile_code>
<time_recording_variant>DURATION</time_recording_variant>
<time_type_profile_code>NL20+/CI+</time_type_profile_code>
<timezone>Europe/Amsterdam</timezone>
<workingDaysPerWeek>5.0</workingDaysPerWeek>
<workschedule_code>DUMMY</workschedule_code>
</job_information>
<job_information>
<shift_factor>0.0</shift_factor>
<shift_rate>0.0</shift_rate>
<standard_hours>0.0</standard_hours>
<start_date>2020-10-01</start_date>
<timezone>Europe/Amsterdam</timezone>
<workingDaysPerWeek>0.0</workingDaysPerWeek>
</job_information>
<job_event_information>
<action>INSERT</action>
<created_on_timestamp>2020-08-01T20:00:48.000Z</created_on_timestamp>
<event>5</event>
<event_date>2020-08-01</event_date>
<event_reason>DATACHG</event_reason>
<seq_number>1</seq_number>
</job_event_information>
</employment_information>
</person>
<execution_timestamp>2020-08-17T14:00:48.000Z</execution_timestamp>
<version_id>2005P0</version_id>
</CompoundEmployee>
</queryCompoundEmployeeResponse>
我使用的 XSL 是这样的:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="queryCompoundEmployeeResponse/CompoundEmployee/person/employment_information">
<xsl:copy>
<xsl:apply-templates select="job_information">
<!-- concat year, month, day -->
<xsl:sort select="concat(
substring(start_date, 1, 4),
substring(start_date, 6, 2),
substring(start_date, 9, 2)
)" order="ascending" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
结果是这样的(摘录)
如您所见,排序没问题,但来自就业信息的其他孩子已经走了。 我如何才能保留它们?我错过了什么?
<employment_information>
<job_information>
<shift_factor>0.0</shift_factor>
<shift_rate>0.0</shift_rate>
<standard_hours>0.0</standard_hours>
<start_date>2020-10-01</start_date>
<timezone>Europe/Amsterdam</timezone>
<workingDaysPerWeek>0.0</workingDaysPerWeek>
</job_information>
<job_information>
<action>CHANGE</action>
<shift_factor>0.0</shift_factor>
<shift_rate>0.0</shift_rate>
<standard_hours>38.0</standard_hours>
<start_date>2020-10-10</start_date>
<time_recording_admissibility_code>NL</time_recording_admissibility_code>
<time_recording_profile_code>NL</time_recording_profile_code>
<time_recording_variant>DURATION</time_recording_variant>
<time_type_profile_code>NL20+/CI+</time_type_profile_code>
<timezone>Europe/Amsterdam</timezone>
<workingDaysPerWeek>5.0</workingDaysPerWeek>
<workschedule_code>DUMMY</workschedule_code>
</job_information>
</employment_information>
【问题讨论】: