仅当子节点条件匹配时才显示父节点值

发布于 2025-01-09 15:32:03 字数 30793 浏览 0 评论 0原文

示例源 XML:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <queryResponse xmlns="urn:sfobject.sfapi.successfactors.com" xmlns:ns2="urn:fault.sfapi.successfactors.com">
      <result>
        <sfobject>
          <id>18348</id>
          <type>CompoundEmployee</type>
          <person>
            <created_by>Adminhaiku1</created_by>
            <created_on_timestamp>2018-10-13T18:46:36.000Z</created_on_timestamp>
            <custom_string1>90024719</custom_string1>
            <custom_string2>fgutsch</custom_string2>
            <date_of_birth>1971-08-24</date_of_birth>
            <logon_user_id>01037864</logon_user_id>
            <logon_user_is_active>true</logon_user_is_active>
            <logon_user_name>fgutsch</logon_user_name>
            <person_id_external>GI00006411</person_id_external>
            <place_of_birth>Hamburg</place_of_birth>
            <personal_information>
              <end_date>9999-12-31</end_date>
              <first_name>Rodrigo</first_name>
              <first_name_alt1>Rodrigo</first_name_alt1>
              <formal_name>Rodrigo Lacey</formal_name>
              <gender>M</gender>
              <last_name>Lacey</last_name>
              <last_name_alt1>Lacey</last_name_alt1>
              <name_format_code>Complete</name_format_code>
              <salutation>mr</salutation>
              <start_date>2019-01-01</start_date>
            </personal_information>
            <personal_information>
              <created_by>28007677</created_by>
              <end_date>2018-12-31</end_date>
              <first_name>Rodrigo</first_name>
              <formal_name>Rodrigo Lacey</formal_name>
              <gender>M</gender>
              <last_name>Lacey</last_name>
              <name_format_code>Complete</name_format_code>
              <nationality>DE</nationality>
              <native_preferred_lang>17</native_preferred_lang>
              <salutation>mr</salutation>
              <start_date>2018-12-13</start_date>
            </personal_information>
            <personal_information>
              <created_by>Adminhaiku1</created_by>
              <end_date>2018-12-12</end_date>
              <first_name>Rodrigo</first_name>
              <formal_name>Rodrigo Lacey</formal_name>
              <gender>M</gender>
              <last_name>Lacey</last_name>
              <name_format_code>Complete</name_format_code>
              <nationality>DE</nationality>
              <native_preferred_lang>17</native_preferred_lang>
              <salutation>mr</salutation>
              <start_date>2018-11-01</start_date>
            </personal_information>
            <email_information>
              <created_by>x2sfapiBIDS</created_by>
              <email_address>someone@test_boehringer.com</email_address>
              <email_type>B</email_type>
              <isPrimary>true</isPrimary>
            </email_information>
            <employment_information>
              <assignment_class>ST</assignment_class>
              <assignmentIdExternal>01037864</assignmentIdExternal>
              <created_by>Adminhaiku1</created_by>
              <created_on_timestamp>2018-10-13T18:46:36.000Z</created_on_timestamp>
              <custom_date1>1995-04-17</custom_date1>
              <employment_id>18348</employment_id>
              <originalStartDate>1995-04-17</originalStartDate>
              <sourceOfRecord>EC</sourceOfRecord>
              <start_date>1999-03-01</start_date>
              <user_id>01037864</user_id>
              <job_information>
                <business_unit>70001634</business_unit>
                <company>0011</company>
                <company_territory_code>DEU</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <department>20000045</department>
                <division>SF_Gen.Administration</division>
                <employee_class>1</employee_class>
                <employee_type>1b</employee_type>
                <employment_type>DEU_121</employment_type>
                <emplStatus>D</emplStatus>
                <end_date>9999-12-31</end_date>
                <start_date>2020-09-01</start_date>
                <supervisor_level>99</supervisor_level>
              </job_information>
              <job_information>
                <business_unit>70001634</business_unit>
                <company>0011</company>
                <company_territory_code>DEU</company_territory_code>
                <cost_center>DEZ0885500</cost_center>
                <created_by>01056122</created_by>
                <department>20000045</department>
                <division>SF_Gen.Administration</division>
                <employee_class>1</employee_class>
                <employee_type>1b</employee_type>
                <employment_type>DEU_121</employment_type>
                <emplStatus>D</emplStatus>
                <end_date>2020-08-31</end_date>
                <start_date>2020-08-15</start_date>
                <supervisor_level>99</supervisor_level>
              </job_information>
              <job_information>
                <business_unit>70001634</business_unit>
                <company>0011</company>
                <company_territory_code>DEU</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>DEZ0885500</cost_center>
                <created_by>55207745</created_by>
                <created_on>2020-02-26</created_on>
                <created_on_timestamp>2020-02-26T12:29:37.000Z</created_on_timestamp>
                <department>20000045</department>
                <division>SF_Gen.Administration</division>
                <employee_class>1</employee_class>
                <employee_type>1b</employee_type>
                <employment_type>DEU_121</employment_type>
                <emplStatus>D</emplStatus>
                <end_date>2020-08-14</end_date>
                <start_date>2020-01-01</start_date>
                <supervisor_level>99</supervisor_level>
              </job_information>
              <job_information>
                <business_unit>70001634</business_unit>
                <company>0011</company>
                <company_territory_code>DEU</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>DEZ0885500</cost_center>
                <created_by>55207745</created_by>
                <created_on>2019-12-11</created_on>
                <created_on_timestamp>2019-12-11T13:11:40.000Z</created_on_timestamp>
                <department>20000045</department>
                <division>SF_Gen.Administration</division>
                <employee_class>1</employee_class>
                <employee_type>1b</employee_type>
                <employment_type>DEU_121</employment_type>
                <emplStatus>D</emplStatus>
                <end_date>2019-12-31</end_date>
                <start_date>2019-12-01</start_date>
                <supervisor_level>2</supervisor_level>
              </job_information>
              <job_information>
                <business_unit>70001634</business_unit>
                <company>0011</company>
                <company_territory_code>DEU</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>DEZ0885500</cost_center>
                <created_by>01047427</created_by>
                <created_on>2018-12-04</created_on>
                <created_on_timestamp>2018-12-04T17:40:31.000Z</created_on_timestamp>
                <department>20003001</department>
                <division>SF_Gen.Administration</division>
                <employee_class>1</employee_class>
                <employee_type>1b</employee_type>
                <employment_type>DEU_121</employment_type>
                <emplStatus>D</emplStatus>
                <end_date>2019-11-30</end_date>
                <start_date>2019-08-16</start_date>
                <supervisor_level>2</supervisor_level>
              </job_information>
              <job_information>
                <business_unit>70001634</business_unit>
                <company>0011</company>
                <company_territory_code>DEU</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>DEZ0885500</cost_center>
                <created_by>48100821</created_by>
                <created_on>2019-11-06</created_on>
                <created_on_timestamp>2019-11-06T14:33:24.000Z</created_on_timestamp>
                <department>20003001</department>
                <division>SF_Gen.Administration</division>
                <employee_class>1</employee_class>
                <employee_type>1b</employee_type>
                <employment_type>DEU_121</employment_type>
                <emplStatus>D</emplStatus>
                <end_date>2019-08-15</end_date>
                <start_date>2019-01-01</start_date>
                <supervisor_level>2</supervisor_level>
              </job_information>
              <job_information>
                <business_unit>70001640</business_unit>
                <company>0010</company>
                <company_territory_code>DEU</company_territory_code>
                <companyEntryDate>2017-07-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>DEZ0704311</cost_center>
                <created_by>Adminhaiku1</created_by>
                <created_on>2018-10-18</created_on>
                <created_on_timestamp>2018-10-18T04:19:50.000Z</created_on_timestamp>
                <department>20025776</department>
                <division>SF_Gen.Administration</division>
                <employee_class>1</employee_class>
                <employee_type>1a</employee_type>
                <employment_type>DEU_116</employment_type>
                <emplStatus>A</emplStatus>
                <end_date>2018-12-31</end_date>
                <start_date>2018-11-01</start_date>
                <supervisor_level>2</supervisor_level>
              </job_information>
              <job_information>
                <company>0010</company>
                <company_territory_code>DEU</company_territory_code>
                <companyEntryDate>1999-03-01</companyEntryDate>
                <contract_type>O</contract_type>
                <created_by>Adminhaiku1</created_by>
                <created_on>2018-10-16</created_on>
                <created_on_timestamp>2018-10-16T08:48:13.000Z</created_on_timestamp>
                <custom_double1>37.5</custom_double1>
                <custom_string9>A</custom_string9>
                <employee_class>1</employee_class>
                <employee_type>1a</employee_type>
                <emplStatus>A</emplStatus>
                <end_date>2018-10-31</end_date>
                <start_date>1999-03-01</start_date>
              </job_information>
            </employment_information>
            <employment_information>
              <assignment_class>GA</assignment_class>
              <assignment_type>GAP17+</assignment_type>
              <assignmentIdExternal>55207227</assignmentIdExternal>
              <created_by>55218289</created_by>
              <created_on_timestamp>2021-07-06T12:38:38.000Z</created_on_timestamp>
              <direct_reports>17</direct_reports>
              <employment_id>76558</employment_id>
              <last_modified_by>55218289</last_modified_by>
              <last_modified_on>2021-07-09T10:01:18.000Z</last_modified_on>
              <planned_end_date>2023-12-31</planned_end_date>
              <sourceOfRecord>EC</sourceOfRecord>
              <start_date>2019-01-01</start_date>
              <user_id>55207227</user_id>
              <job_information>
                <business_unit>70001634</business_unit>
                <company>0270</company>
                <company_territory_code>CHN</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>CN1000</cost_center>
                <created_by>55220416</created_by>
                <created_on>2021-12-01</created_on>
                <created_on_timestamp>2021-12-01T16:38:00.000Z</created_on_timestamp>
                <department>20009269</department>
                <division>SF_Gen.Administration</division>
                <employee_class>1</employee_class>
                <employee_type>1c</employee_type>
                <employment_type>CHN_5</employment_type>
                <emplStatus>A</emplStatus>
                <end_date>9999-12-31</end_date>
                <start_date>2021-01-01</start_date>
                <supervisor_level>2</supervisor_level>
              </job_information>
              <job_information>
                <business_unit>70063436</business_unit>
                <company>0270</company>
                <company_territory_code>CHN</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>CN1000</cost_center>
                <created_by>01056122</created_by>
                <created_on>2020-08-14</created_on>
                <created_on_timestamp>2020-08-14T10:21:19.000Z</created_on_timestamp>
                <department>20009269</department>
                <division>SF_Business_Management</division>
                <employee_class>1</employee_class>
                <employee_type>1c</employee_type>
                <employment_type>CHN_5</employment_type>
                <emplStatus>A</emplStatus>
                <end_date>2020-12-31</end_date>
                <start_date>2020-09-01</start_date>
                <supervisor_level>2</supervisor_level>
              </job_information>
              <job_information>
                <business_unit>70063436</business_unit>
                <company>0270</company>
                <company_territory_code>CHN</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>CN1000</cost_center>
                <created_by>01056122</created_by>
                <created_on>2020-08-13</created_on>
                <created_on_timestamp>2020-08-13T15:10:59.000Z</created_on_timestamp>
                <department>20009269</department>
                <division>SF_Business_Management</division>
                <employee_class>1</employee_class>
                <employee_type>1c</employee_type>
                <employment_type>CHN_5</employment_type>
                <emplStatus>A</emplStatus>
                <end_date>2020-08-31</end_date>
                <start_date>2020-08-15</start_date>
                <supervisor_level>2</supervisor_level>
                <timezone>PRC</timezone>
                <working_time_directive>false</working_time_directive>
                <workingDaysPerWeek>0.0</workingDaysPerWeek>
              </job_information>
              <job_information>
                <business_unit>70063436</business_unit>
                <company>0270</company>
                <company_territory_code>CHN</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>CN1000</cost_center>
                <created_by>48100840</created_by>
                <created_on>2020-02-28</created_on>
                <created_on_timestamp>2020-02-28T03:39:29.000Z</created_on_timestamp>
                <department>20009269</department>
                <division>SF_Business_Management</division>
                <employee_class>1</employee_class>
                <employee_type>1c</employee_type>
                <employment_type>CHN_5</employment_type>
                <emplStatus>A</emplStatus>
                <end_date>2020-08-14</end_date>
                <start_date>2020-02-01</start_date>
                <supervisor_level>2</supervisor_level>
                <timezone>PRC</timezone>
                <working_time_directive>false</working_time_directive>
                <workingDaysPerWeek>0.0</workingDaysPerWeek>
              </job_information>
              <job_information>
                <business_unit>70063436</business_unit>
                <company>0270</company>
                <company_territory_code>CHN</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>CN1000</cost_center>
                <created_by>55207745</created_by>
                <created_on>2019-12-26</created_on>
                <created_on_timestamp>2019-12-26T09:43:18.000Z</created_on_timestamp>
                <department>20009269</department>
                <division>SF_Business_Management</division>
                <employee_class>1</employee_class>
                <employee_type>1c</employee_type>
                <employment_type>CHN_5</employment_type>
                <emplStatus>A</emplStatus>
                <end_date>2020-01-31</end_date>
                <start_date>2020-01-01</start_date>
                <supervisor_level>2</supervisor_level>
                <timezone>PRC</timezone>
                <working_time_directive>false</working_time_directive>
                <workingDaysPerWeek>0.0</workingDaysPerWeek>
              </job_information>
              <job_information>
                <business_unit>70063436</business_unit>
                <company>0270</company>
                <company_territory_code>CHN</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>CN1000</cost_center>
                <created_by>48100821</created_by>
                <created_on>2019-07-31</created_on>
                <created_on_timestamp>2019-07-31T18:40:50.000Z</created_on_timestamp>
                <department>20009269</department>
                <division>SF_Business_Management</division>
                <employee_class>1</employee_class>
                <employee_type>1c</employee_type>
                <employment_type>CHN_5</employment_type>
                <emplStatus>A</emplStatus>
                <end_date>2019-12-31</end_date>
                <start_date>2019-08-01</start_date>
                <supervisor_level>2</supervisor_level>
                <timezone>PRC</timezone>
                <working_time_directive>false</working_time_directive>
                <workingDaysPerWeek>0.0</workingDaysPerWeek>
              </job_information>
              <job_information>
                <business_unit>70063436</business_unit>
                <company>0270</company>
                <company_territory_code>CHN</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>CN1000</cost_center>
                <created_by>01047427</created_by>
                <created_on>2018-12-04</created_on>
                <created_on_timestamp>2018-12-04T17:40:28.000Z</created_on_timestamp>
                <department>20009269</department>
                <division>SF_Business_Management</division>
                <employee_class>1</employee_class>
                <employee_type>1c</employee_type>
                <emplStatus>A</emplStatus>
                <end_date>2019-07-31</end_date>
                <start_date>2019-01-01</start_date>
                <supervisor_level>2</supervisor_level>
                <timezone>PRC</timezone>
                <workingDaysPerWeek>0.0</workingDaysPerWeek>
              </job_information>
            </employment_information>
          </person>
          <execution_timestamp>2022-02-25T01:10:13.000Z</execution_timestamp>
          <version_id>2111P0</version_id>
        </sfobject>
        <numResults>1</numResults>
        <hasMore>false</hasMore>
        <querySessionId>f473261d-838f-455c-a5ed-fee8707fd5e1</querySessionId>
      </result>
    </queryResponse>
  </S:Body>
</S:Envelope>

团队,

我需要格式化上述 xml 并生成 json 输出。格式化条件如下。

需要识别 start_date <= 今天的 job_information AND (end_date >today 或 end_date 为 null ) AND company_territory_code='CHN'

如果上述条件匹配,则检查其 start_date <= 今天 AND ( end_date >today 或 end_date 为 null )

如果上述条件(1& 2)有效,则从父节点 individual_information 读取具有以下属性的属性start_date <= 今天 AND (end_date >today 或 end_date 为 null )

email_address 来自节点 email_information 仅那些 email_type =B (只有一个存在

最后来自节点的一些属性

下面是我尝试过但无法带上父节点的 xslt每个部分的条件 1 和 1 中的信息不确定是否可以采取其他方法。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:hm="urn:sfobject.sfapi.successfactors.com" exclude-result-prefixes="hm">
  <xsl:output method="text" encoding="UTF-8" />
  <xsl:param name="policydate" />
  <xsl:template match="/">
    <xsl:text>{</xsl:text>
    <xsl:text>"results":{</xsl:text>
    <xsl:text>"sfobject":[</xsl:text>
    <xsl:for-each select="//hm:sfobject">
      <!-- person -->
      <xsl:text>{</xsl:text>
      <xsl:text>"GICode":"</xsl:text>
      <xsl:value-of select="hm:person/hm:person_id_external" />
      <xsl:text>",</xsl:text>
      <!-- email_information -->
      <xsl:for-each select="hm:person/hm:email_information">
        <xsl:sort select="hm:last_modified_on" data-type="text" order="descending" />
        <xsl:choose>
          <xsl:when test="hm:email_type='B'">
            <xsl:text>"emailAddress":"</xsl:text>
            <xsl:value-of select="./hm:email_address" />
            <xsl:text>",</xsl:text>
          </xsl:when>
        </xsl:choose>
      </xsl:for-each>
      <!-- personal_information -->
      <xsl:for-each select="hm:person/hm:personal_information">
        <xsl:choose>
          <xsl:when test="hm:start_date&lt;= $policydate and  $policydate &lt;=hm:end_date or not(hm:end_date)">
            <!-- employment_information and job_information -->
            <xsl:for-each select="hm:person/hm:employment_information">
              <xsl:choose>
                <!-- Check employment_information dates -->
                <xsl:when test=" hm:start_date&lt;= $policydate and  $policydate &lt;=hm:end_date or not(hm:end_date)">
                  <xsl:for-each select="hm:job_information">
                    <xsl:choose>
                      <!-- Check job_information dates and country  -->
                      <xsl:when test=" hm:company_territory_code='CHN' and hm:start_date&lt;= $policydate and  $policydate &lt;=hm:end_date or not(hm:end_date)">
                        <!-- personal_information -->
                        <xsl:text>"lastName":"</xsl:text>
                        <xsl:value-of select="ancestor::hm:personal_information/hm:last_name" />
                        <xsl:text>",</xsl:text>
                        <xsl:text>"lastNameAlternatives":"</xsl:text>
                        <xsl:value-of select="ancestor::hm:personal_information/hm:last_name_alt1" />
                        <xsl:text>",</xsl:text>
                        <!-- employment_information -->
                        <xsl:text>"employeeNumber":"</xsl:text>
                        <xsl:value-of select="ancestor::hm:employment_information/hm:user_id" />
                        <xsl:text>",</xsl:text>
                        <!-- job_information -->
                        <xsl:text>"supervisorEmpNumber":"</xsl:text>
                        <xsl:value-of select="./hm:manager_id" />
                        <xsl:text>",</xsl:text>
                        <xsl:text>"companyCode":"</xsl:text>
                        <xsl:value-of select="./hm:company" />
                        <xsl:text>"</xsl:text>
                      </xsl:when>
                    </xsl:choose>
                  </xsl:for-each>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
          </xsl:when>
        </xsl:choose>
      </xsl:for-each>
      <!-- Closing part of Json Array -->
      <xsl:choose>
        <xsl:when test="position() != last()">
          <xsl:text>},</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>}</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
    <xsl:text>],</xsl:text>
    <xsl:text>"numResults":"</xsl:text>
    <xsl:value-of select="//hm:result/hm:numResults" />
    <xsl:text>",</xsl:text>
    <xsl:choose>
      <xsl:when test="//hm:result/hm:hasMore='true'">
        <xsl:text>"sessionId":"</xsl:text>
        <xsl:value-of select="$sessionId" />
        <xsl:text>",</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>"sessionId":"</xsl:text>
        <xsl:value-of select="$sessionId" />
        <xsl:text>"</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>}</xsl:text>
    <xsl:text>}</xsl:text>
  </xsl:template>
</xsl:stylesheet>

Sample Source XML:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <queryResponse xmlns="urn:sfobject.sfapi.successfactors.com" xmlns:ns2="urn:fault.sfapi.successfactors.com">
      <result>
        <sfobject>
          <id>18348</id>
          <type>CompoundEmployee</type>
          <person>
            <created_by>Adminhaiku1</created_by>
            <created_on_timestamp>2018-10-13T18:46:36.000Z</created_on_timestamp>
            <custom_string1>90024719</custom_string1>
            <custom_string2>fgutsch</custom_string2>
            <date_of_birth>1971-08-24</date_of_birth>
            <logon_user_id>01037864</logon_user_id>
            <logon_user_is_active>true</logon_user_is_active>
            <logon_user_name>fgutsch</logon_user_name>
            <person_id_external>GI00006411</person_id_external>
            <place_of_birth>Hamburg</place_of_birth>
            <personal_information>
              <end_date>9999-12-31</end_date>
              <first_name>Rodrigo</first_name>
              <first_name_alt1>Rodrigo</first_name_alt1>
              <formal_name>Rodrigo Lacey</formal_name>
              <gender>M</gender>
              <last_name>Lacey</last_name>
              <last_name_alt1>Lacey</last_name_alt1>
              <name_format_code>Complete</name_format_code>
              <salutation>mr</salutation>
              <start_date>2019-01-01</start_date>
            </personal_information>
            <personal_information>
              <created_by>28007677</created_by>
              <end_date>2018-12-31</end_date>
              <first_name>Rodrigo</first_name>
              <formal_name>Rodrigo Lacey</formal_name>
              <gender>M</gender>
              <last_name>Lacey</last_name>
              <name_format_code>Complete</name_format_code>
              <nationality>DE</nationality>
              <native_preferred_lang>17</native_preferred_lang>
              <salutation>mr</salutation>
              <start_date>2018-12-13</start_date>
            </personal_information>
            <personal_information>
              <created_by>Adminhaiku1</created_by>
              <end_date>2018-12-12</end_date>
              <first_name>Rodrigo</first_name>
              <formal_name>Rodrigo Lacey</formal_name>
              <gender>M</gender>
              <last_name>Lacey</last_name>
              <name_format_code>Complete</name_format_code>
              <nationality>DE</nationality>
              <native_preferred_lang>17</native_preferred_lang>
              <salutation>mr</salutation>
              <start_date>2018-11-01</start_date>
            </personal_information>
            <email_information>
              <created_by>x2sfapiBIDS</created_by>
              <email_address>someone@test_boehringer.com</email_address>
              <email_type>B</email_type>
              <isPrimary>true</isPrimary>
            </email_information>
            <employment_information>
              <assignment_class>ST</assignment_class>
              <assignmentIdExternal>01037864</assignmentIdExternal>
              <created_by>Adminhaiku1</created_by>
              <created_on_timestamp>2018-10-13T18:46:36.000Z</created_on_timestamp>
              <custom_date1>1995-04-17</custom_date1>
              <employment_id>18348</employment_id>
              <originalStartDate>1995-04-17</originalStartDate>
              <sourceOfRecord>EC</sourceOfRecord>
              <start_date>1999-03-01</start_date>
              <user_id>01037864</user_id>
              <job_information>
                <business_unit>70001634</business_unit>
                <company>0011</company>
                <company_territory_code>DEU</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <department>20000045</department>
                <division>SF_Gen.Administration</division>
                <employee_class>1</employee_class>
                <employee_type>1b</employee_type>
                <employment_type>DEU_121</employment_type>
                <emplStatus>D</emplStatus>
                <end_date>9999-12-31</end_date>
                <start_date>2020-09-01</start_date>
                <supervisor_level>99</supervisor_level>
              </job_information>
              <job_information>
                <business_unit>70001634</business_unit>
                <company>0011</company>
                <company_territory_code>DEU</company_territory_code>
                <cost_center>DEZ0885500</cost_center>
                <created_by>01056122</created_by>
                <department>20000045</department>
                <division>SF_Gen.Administration</division>
                <employee_class>1</employee_class>
                <employee_type>1b</employee_type>
                <employment_type>DEU_121</employment_type>
                <emplStatus>D</emplStatus>
                <end_date>2020-08-31</end_date>
                <start_date>2020-08-15</start_date>
                <supervisor_level>99</supervisor_level>
              </job_information>
              <job_information>
                <business_unit>70001634</business_unit>
                <company>0011</company>
                <company_territory_code>DEU</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>DEZ0885500</cost_center>
                <created_by>55207745</created_by>
                <created_on>2020-02-26</created_on>
                <created_on_timestamp>2020-02-26T12:29:37.000Z</created_on_timestamp>
                <department>20000045</department>
                <division>SF_Gen.Administration</division>
                <employee_class>1</employee_class>
                <employee_type>1b</employee_type>
                <employment_type>DEU_121</employment_type>
                <emplStatus>D</emplStatus>
                <end_date>2020-08-14</end_date>
                <start_date>2020-01-01</start_date>
                <supervisor_level>99</supervisor_level>
              </job_information>
              <job_information>
                <business_unit>70001634</business_unit>
                <company>0011</company>
                <company_territory_code>DEU</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>DEZ0885500</cost_center>
                <created_by>55207745</created_by>
                <created_on>2019-12-11</created_on>
                <created_on_timestamp>2019-12-11T13:11:40.000Z</created_on_timestamp>
                <department>20000045</department>
                <division>SF_Gen.Administration</division>
                <employee_class>1</employee_class>
                <employee_type>1b</employee_type>
                <employment_type>DEU_121</employment_type>
                <emplStatus>D</emplStatus>
                <end_date>2019-12-31</end_date>
                <start_date>2019-12-01</start_date>
                <supervisor_level>2</supervisor_level>
              </job_information>
              <job_information>
                <business_unit>70001634</business_unit>
                <company>0011</company>
                <company_territory_code>DEU</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>DEZ0885500</cost_center>
                <created_by>01047427</created_by>
                <created_on>2018-12-04</created_on>
                <created_on_timestamp>2018-12-04T17:40:31.000Z</created_on_timestamp>
                <department>20003001</department>
                <division>SF_Gen.Administration</division>
                <employee_class>1</employee_class>
                <employee_type>1b</employee_type>
                <employment_type>DEU_121</employment_type>
                <emplStatus>D</emplStatus>
                <end_date>2019-11-30</end_date>
                <start_date>2019-08-16</start_date>
                <supervisor_level>2</supervisor_level>
              </job_information>
              <job_information>
                <business_unit>70001634</business_unit>
                <company>0011</company>
                <company_territory_code>DEU</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>DEZ0885500</cost_center>
                <created_by>48100821</created_by>
                <created_on>2019-11-06</created_on>
                <created_on_timestamp>2019-11-06T14:33:24.000Z</created_on_timestamp>
                <department>20003001</department>
                <division>SF_Gen.Administration</division>
                <employee_class>1</employee_class>
                <employee_type>1b</employee_type>
                <employment_type>DEU_121</employment_type>
                <emplStatus>D</emplStatus>
                <end_date>2019-08-15</end_date>
                <start_date>2019-01-01</start_date>
                <supervisor_level>2</supervisor_level>
              </job_information>
              <job_information>
                <business_unit>70001640</business_unit>
                <company>0010</company>
                <company_territory_code>DEU</company_territory_code>
                <companyEntryDate>2017-07-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>DEZ0704311</cost_center>
                <created_by>Adminhaiku1</created_by>
                <created_on>2018-10-18</created_on>
                <created_on_timestamp>2018-10-18T04:19:50.000Z</created_on_timestamp>
                <department>20025776</department>
                <division>SF_Gen.Administration</division>
                <employee_class>1</employee_class>
                <employee_type>1a</employee_type>
                <employment_type>DEU_116</employment_type>
                <emplStatus>A</emplStatus>
                <end_date>2018-12-31</end_date>
                <start_date>2018-11-01</start_date>
                <supervisor_level>2</supervisor_level>
              </job_information>
              <job_information>
                <company>0010</company>
                <company_territory_code>DEU</company_territory_code>
                <companyEntryDate>1999-03-01</companyEntryDate>
                <contract_type>O</contract_type>
                <created_by>Adminhaiku1</created_by>
                <created_on>2018-10-16</created_on>
                <created_on_timestamp>2018-10-16T08:48:13.000Z</created_on_timestamp>
                <custom_double1>37.5</custom_double1>
                <custom_string9>A</custom_string9>
                <employee_class>1</employee_class>
                <employee_type>1a</employee_type>
                <emplStatus>A</emplStatus>
                <end_date>2018-10-31</end_date>
                <start_date>1999-03-01</start_date>
              </job_information>
            </employment_information>
            <employment_information>
              <assignment_class>GA</assignment_class>
              <assignment_type>GAP17+</assignment_type>
              <assignmentIdExternal>55207227</assignmentIdExternal>
              <created_by>55218289</created_by>
              <created_on_timestamp>2021-07-06T12:38:38.000Z</created_on_timestamp>
              <direct_reports>17</direct_reports>
              <employment_id>76558</employment_id>
              <last_modified_by>55218289</last_modified_by>
              <last_modified_on>2021-07-09T10:01:18.000Z</last_modified_on>
              <planned_end_date>2023-12-31</planned_end_date>
              <sourceOfRecord>EC</sourceOfRecord>
              <start_date>2019-01-01</start_date>
              <user_id>55207227</user_id>
              <job_information>
                <business_unit>70001634</business_unit>
                <company>0270</company>
                <company_territory_code>CHN</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>CN1000</cost_center>
                <created_by>55220416</created_by>
                <created_on>2021-12-01</created_on>
                <created_on_timestamp>2021-12-01T16:38:00.000Z</created_on_timestamp>
                <department>20009269</department>
                <division>SF_Gen.Administration</division>
                <employee_class>1</employee_class>
                <employee_type>1c</employee_type>
                <employment_type>CHN_5</employment_type>
                <emplStatus>A</emplStatus>
                <end_date>9999-12-31</end_date>
                <start_date>2021-01-01</start_date>
                <supervisor_level>2</supervisor_level>
              </job_information>
              <job_information>
                <business_unit>70063436</business_unit>
                <company>0270</company>
                <company_territory_code>CHN</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>CN1000</cost_center>
                <created_by>01056122</created_by>
                <created_on>2020-08-14</created_on>
                <created_on_timestamp>2020-08-14T10:21:19.000Z</created_on_timestamp>
                <department>20009269</department>
                <division>SF_Business_Management</division>
                <employee_class>1</employee_class>
                <employee_type>1c</employee_type>
                <employment_type>CHN_5</employment_type>
                <emplStatus>A</emplStatus>
                <end_date>2020-12-31</end_date>
                <start_date>2020-09-01</start_date>
                <supervisor_level>2</supervisor_level>
              </job_information>
              <job_information>
                <business_unit>70063436</business_unit>
                <company>0270</company>
                <company_territory_code>CHN</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>CN1000</cost_center>
                <created_by>01056122</created_by>
                <created_on>2020-08-13</created_on>
                <created_on_timestamp>2020-08-13T15:10:59.000Z</created_on_timestamp>
                <department>20009269</department>
                <division>SF_Business_Management</division>
                <employee_class>1</employee_class>
                <employee_type>1c</employee_type>
                <employment_type>CHN_5</employment_type>
                <emplStatus>A</emplStatus>
                <end_date>2020-08-31</end_date>
                <start_date>2020-08-15</start_date>
                <supervisor_level>2</supervisor_level>
                <timezone>PRC</timezone>
                <working_time_directive>false</working_time_directive>
                <workingDaysPerWeek>0.0</workingDaysPerWeek>
              </job_information>
              <job_information>
                <business_unit>70063436</business_unit>
                <company>0270</company>
                <company_territory_code>CHN</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>CN1000</cost_center>
                <created_by>48100840</created_by>
                <created_on>2020-02-28</created_on>
                <created_on_timestamp>2020-02-28T03:39:29.000Z</created_on_timestamp>
                <department>20009269</department>
                <division>SF_Business_Management</division>
                <employee_class>1</employee_class>
                <employee_type>1c</employee_type>
                <employment_type>CHN_5</employment_type>
                <emplStatus>A</emplStatus>
                <end_date>2020-08-14</end_date>
                <start_date>2020-02-01</start_date>
                <supervisor_level>2</supervisor_level>
                <timezone>PRC</timezone>
                <working_time_directive>false</working_time_directive>
                <workingDaysPerWeek>0.0</workingDaysPerWeek>
              </job_information>
              <job_information>
                <business_unit>70063436</business_unit>
                <company>0270</company>
                <company_territory_code>CHN</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>CN1000</cost_center>
                <created_by>55207745</created_by>
                <created_on>2019-12-26</created_on>
                <created_on_timestamp>2019-12-26T09:43:18.000Z</created_on_timestamp>
                <department>20009269</department>
                <division>SF_Business_Management</division>
                <employee_class>1</employee_class>
                <employee_type>1c</employee_type>
                <employment_type>CHN_5</employment_type>
                <emplStatus>A</emplStatus>
                <end_date>2020-01-31</end_date>
                <start_date>2020-01-01</start_date>
                <supervisor_level>2</supervisor_level>
                <timezone>PRC</timezone>
                <working_time_directive>false</working_time_directive>
                <workingDaysPerWeek>0.0</workingDaysPerWeek>
              </job_information>
              <job_information>
                <business_unit>70063436</business_unit>
                <company>0270</company>
                <company_territory_code>CHN</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>CN1000</cost_center>
                <created_by>48100821</created_by>
                <created_on>2019-07-31</created_on>
                <created_on_timestamp>2019-07-31T18:40:50.000Z</created_on_timestamp>
                <department>20009269</department>
                <division>SF_Business_Management</division>
                <employee_class>1</employee_class>
                <employee_type>1c</employee_type>
                <employment_type>CHN_5</employment_type>
                <emplStatus>A</emplStatus>
                <end_date>2019-12-31</end_date>
                <start_date>2019-08-01</start_date>
                <supervisor_level>2</supervisor_level>
                <timezone>PRC</timezone>
                <working_time_directive>false</working_time_directive>
                <workingDaysPerWeek>0.0</workingDaysPerWeek>
              </job_information>
              <job_information>
                <business_unit>70063436</business_unit>
                <company>0270</company>
                <company_territory_code>CHN</company_territory_code>
                <companyEntryDate>2019-01-01</companyEntryDate>
                <contract_type>O</contract_type>
                <cost_center>CN1000</cost_center>
                <created_by>01047427</created_by>
                <created_on>2018-12-04</created_on>
                <created_on_timestamp>2018-12-04T17:40:28.000Z</created_on_timestamp>
                <department>20009269</department>
                <division>SF_Business_Management</division>
                <employee_class>1</employee_class>
                <employee_type>1c</employee_type>
                <emplStatus>A</emplStatus>
                <end_date>2019-07-31</end_date>
                <start_date>2019-01-01</start_date>
                <supervisor_level>2</supervisor_level>
                <timezone>PRC</timezone>
                <workingDaysPerWeek>0.0</workingDaysPerWeek>
              </job_information>
            </employment_information>
          </person>
          <execution_timestamp>2022-02-25T01:10:13.000Z</execution_timestamp>
          <version_id>2111P0</version_id>
        </sfobject>
        <numResults>1</numResults>
        <hasMore>false</hasMore>
        <querySessionId>f473261d-838f-455c-a5ed-fee8707fd5e1</querySessionId>
      </result>
    </queryResponse>
  </S:Body>
</S:Envelope>

Team,

I have an requirement to format the above xml and generate json output. The formatting condition is as below .

Need to identify job_information which is having start_date <= today AND (end_date >today or end_date is null ) AND company_territory_code='CHN'

If above condition match then check for its parent node employment_information which is having start_date <= today AND (end_date >today or end_date is null )

if above condition (1& 2) are valid then read attributes from parent node personal_information for those having start_date <= today AND (end_date >today or end_date is null )

email_address from node email_information only those email_type =B (it will be only one exists

Finally some attributes from node

The below is xslt i have tried but unable to bring parent node information inside condition 1 & 1 for each section . Not sure is there another approach can be done.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:hm="urn:sfobject.sfapi.successfactors.com" exclude-result-prefixes="hm">
  <xsl:output method="text" encoding="UTF-8" />
  <xsl:param name="policydate" />
  <xsl:template match="/">
    <xsl:text>{</xsl:text>
    <xsl:text>"results":{</xsl:text>
    <xsl:text>"sfobject":[</xsl:text>
    <xsl:for-each select="//hm:sfobject">
      <!-- person -->
      <xsl:text>{</xsl:text>
      <xsl:text>"GICode":"</xsl:text>
      <xsl:value-of select="hm:person/hm:person_id_external" />
      <xsl:text>",</xsl:text>
      <!-- email_information -->
      <xsl:for-each select="hm:person/hm:email_information">
        <xsl:sort select="hm:last_modified_on" data-type="text" order="descending" />
        <xsl:choose>
          <xsl:when test="hm:email_type='B'">
            <xsl:text>"emailAddress":"</xsl:text>
            <xsl:value-of select="./hm:email_address" />
            <xsl:text>",</xsl:text>
          </xsl:when>
        </xsl:choose>
      </xsl:for-each>
      <!-- personal_information -->
      <xsl:for-each select="hm:person/hm:personal_information">
        <xsl:choose>
          <xsl:when test="hm:start_date<= $policydate and  $policydate <=hm:end_date or not(hm:end_date)">
            <!-- employment_information and job_information -->
            <xsl:for-each select="hm:person/hm:employment_information">
              <xsl:choose>
                <!-- Check employment_information dates -->
                <xsl:when test=" hm:start_date<= $policydate and  $policydate <=hm:end_date or not(hm:end_date)">
                  <xsl:for-each select="hm:job_information">
                    <xsl:choose>
                      <!-- Check job_information dates and country  -->
                      <xsl:when test=" hm:company_territory_code='CHN' and hm:start_date<= $policydate and  $policydate <=hm:end_date or not(hm:end_date)">
                        <!-- personal_information -->
                        <xsl:text>"lastName":"</xsl:text>
                        <xsl:value-of select="ancestor::hm:personal_information/hm:last_name" />
                        <xsl:text>",</xsl:text>
                        <xsl:text>"lastNameAlternatives":"</xsl:text>
                        <xsl:value-of select="ancestor::hm:personal_information/hm:last_name_alt1" />
                        <xsl:text>",</xsl:text>
                        <!-- employment_information -->
                        <xsl:text>"employeeNumber":"</xsl:text>
                        <xsl:value-of select="ancestor::hm:employment_information/hm:user_id" />
                        <xsl:text>",</xsl:text>
                        <!-- job_information -->
                        <xsl:text>"supervisorEmpNumber":"</xsl:text>
                        <xsl:value-of select="./hm:manager_id" />
                        <xsl:text>",</xsl:text>
                        <xsl:text>"companyCode":"</xsl:text>
                        <xsl:value-of select="./hm:company" />
                        <xsl:text>"</xsl:text>
                      </xsl:when>
                    </xsl:choose>
                  </xsl:for-each>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
          </xsl:when>
        </xsl:choose>
      </xsl:for-each>
      <!-- Closing part of Json Array -->
      <xsl:choose>
        <xsl:when test="position() != last()">
          <xsl:text>},</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>}</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
    <xsl:text>],</xsl:text>
    <xsl:text>"numResults":"</xsl:text>
    <xsl:value-of select="//hm:result/hm:numResults" />
    <xsl:text>",</xsl:text>
    <xsl:choose>
      <xsl:when test="//hm:result/hm:hasMore='true'">
        <xsl:text>"sessionId":"</xsl:text>
        <xsl:value-of select="$sessionId" />
        <xsl:text>",</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>"sessionId":"</xsl:text>
        <xsl:value-of select="$sessionId" />
        <xsl:text>"</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>}</xsl:text>
    <xsl:text>}</xsl:text>
  </xsl:template>
</xsl:stylesheet>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文