基于生效日期和顺序创建 xslt 转换 [英] Creating a xslt transformation based based on effective dates and sequence

查看:33
本文介绍了基于生效日期和顺序创建 xslt 转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 xml 文件.我需要能够基于下面生成一个 csv 文件.然而,问题是如果它的有效时刻相同并且有多个序列属性,它应该只生成一行输出,但是如果有效时刻(只是日期部分)不同,那么它应该根据有效时刻生成一行.我一直在尝试使用 xslt,但到目前为止一直在努力.提供的任何帮助将不胜感激.

I have the following xml file. I need to be able to generate a csv file based on below. However the catch is if its the same effective moment and there are multiple sequence attributes it should generate just one line of output, however if the effective moment (just date part) is different then it should generate a line each based on the effective moment. I have trying to play with xslt but have been struggling so far. Any help provided will be appreciated.

XML 文件

    <?xml version="1.0" encoding="UTF-8"?>
<peci:Workers_Effective_Stack xmlns:peci="urn:com.w/peci">
<peci:Worker>
    <peci:Summary>
        <peci:Integration_Event>14d964101fdb0156e164341b45548d01</peci:Integration_Event>
        <peci:Integration_Sent_On>2018-05-10T08:41:39.375-07:00</peci:Integration_Sent_On>
        <peci:Payroll_Company_Name>West Brooke - Biweekly: B</peci:Payroll_Company_Name>
        <peci:Pay_Group_Country>US</peci:Pay_Group_Country>
        <peci:Pay_Group_Code>j</peci:Pay_Group_Code>
        <peci:Pay_Period_Start>2018-04-30-07:00</peci:Pay_Period_Start>
        <peci:Pay_Period_End>2018-05-13-07:00</peci:Pay_Period_End>
        <peci:Updated_From>2018-05-07T19:50:30.963-07:00</peci:Updated_From>
        <peci:Updated_To>2018-05-10T08:41:39.375-07:00</peci:Updated_To>
        <peci:Effective_From>2018-04-30-07:00</peci:Effective_From>
        <peci:Effective_To>2018-05-13-07:00</peci:Effective_To>
        <peci:Change_Detection>Include only changes entered since the last successful run.</peci:Change_Detection>
        <peci:First_Primary_Run_of_Pay_Period>0</peci:First_Primary_Run_of_Pay_Period>
        <peci:Ad_Hoc_Run>0</peci:Ad_Hoc_Run>
        <peci:Full_Snapshot>0</peci:Full_Snapshot>
        <peci:Worker_Count>2</peci:Worker_Count>
        <peci:Version>1</peci:Version>
    </peci:Summary>
    <peci:Worker>
        <peci:Worker_Summary>
            <peci:WID>rd</peci:WID>
            <peci:Employee_ID>33333</peci:Employee_ID>
            <peci:Name>Test 1</peci:Name>
        </peci:Worker_Summary>
        <peci:Effective_Change peci:Sequence="0">
            <peci:Derived_Event_Code>DTA</peci:Derived_Event_Code>
            <peci:Effective_Moment>2018-05-10T08:29:21.235-07:00</peci:Effective_Moment>
            <peci:Entry_Moment>2018-05-10T08:29:21.235-07:00</peci:Entry_Moment>
            <peci:Worker_Status>
                <peci:Status>Active</peci:Status>
                <peci:Active>1</peci:Active>
                <peci:Active_Status_Date>2018-01-08-08:00</peci:Active_Status_Date>
                <peci:Terminated>0</peci:Terminated>
                <peci:Hire_Date>2018-01-08-08:00</peci:Hire_Date>
                <peci:Original_Hire_Date>2018-01-08-08:00</peci:Original_Hire_Date>
                <peci:Is_Rehire>0</peci:Is_Rehire>
                <peci:Continuous_Service_Date>2018-01-08-08:00</peci:Continuous_Service_Date>
                <peci:First_Day_of_Work>2018-01-08-08:00</peci:First_Day_of_Work>
                <peci:Seniority_Date>2018-01-08-08:00</peci:Seniority_Date>
            </peci:Worker_Status>
        </peci:Effective_Change>
        <peci:Effective_Change peci:Sequence="1">
            <peci:Derived_Event_Code>DTA</peci:Derived_Event_Code>
            <peci:Effective_Moment>2018-05-10T08:31:27.880-07:00</peci:Effective_Moment>
            <peci:Entry_Moment>2018-05-10T08:31:27.880-07:00</peci:Entry_Moment>
            <peci:Worker_Status>
                <peci:Status>Active</peci:Status>
                <peci:Active>1</peci:Active>
                <peci:Active_Status_Date>2018-01-08-08:00</peci:Active_Status_Date>
                <peci:Terminated>0</peci:Terminated>
                <peci:Hire_Date>2018-01-08-08:00</peci:Hire_Date>
                <peci:Original_Hire_Date>2018-01-08-08:00</peci:Original_Hire_Date>
                <peci:Is_Rehire>0</peci:Is_Rehire>
                <peci:Continuous_Service_Date>2018-01-08-08:00</peci:Continuous_Service_Date>
                <peci:First_Day_of_Work>2018-01-08-08:00</peci:First_Day_of_Work>
                <peci:Seniority_Date>2018-01-08-08:00</peci:Seniority_Date>
            </peci:Worker_Status>
        </peci:Effective_Change>
                <peci:Effective_Change peci:Sequence="2">
            <peci:Derived_Event_Code>DTA</peci:Derived_Event_Code>
            <peci:Effective_Moment>2018-05-12T08:29:21.235-07:00</peci:Effective_Moment>
            <peci:Entry_Moment>2018-05-12T08:29:21.235-07:00</peci:Entry_Moment>
            <peci:Worker_Status>
                <peci:Status>Active</peci:Status>
                <peci:Active>1</peci:Active>
                <peci:Active_Status_Date>2018-01-08-08:00</peci:Active_Status_Date>
                <peci:Terminated>0</peci:Terminated>
                <peci:Hire_Date>2018-01-08-08:00</peci:Hire_Date>
                <peci:Original_Hire_Date>2018-01-08-08:00</peci:Original_Hire_Date>
                <peci:Is_Rehire>0</peci:Is_Rehire>
                <peci:Continuous_Service_Date>2018-01-08-08:00</peci:Continuous_Service_Date>
                <peci:First_Day_of_Work>2018-01-08-08:00</peci:First_Day_of_Work>
                <peci:Seniority_Date>2018-01-08-08:00</peci:Seniority_Date>
            </peci:Worker_Status>
        </peci:Effective_Change>
    </peci:Worker>
</peci:Workers_Effective_Stack>

预期输出:3333,2018-10-05,活跃3333,2018-10-10,活跃

Desired Output: 3333,2018-10-05,Active 3333,2018-10-10,Active

推荐答案

假设:

  • 您可以使用 XSLT 2.0,
  • 输出应包含每个 Effective_Moment 的单独行(日期部分),对于每位员工,
  • you can use XSLT 2.0,
  • the output should contain separate row for each Effective_Moment (date part), for each employee,

您可以通过以下方式完成任务:

you can do the task the following way:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:peci="urn:com.w/peci" xpath-default-namespace="urn:com.w/peci">
  <xsl:output method="text" encoding="UTF-8"/>

  <xsl:template match="Workers_Effective_Stack">
    <xsl:for-each-group select="Worker/Effective_Change" group-by=
      "concat(../Worker_Summary/Employee_ID, substring(Effective_Moment,1,10))">
      <xsl:value-of select="../Worker_Summary/Employee_ID"/>
      <xsl:text>,</xsl:text>
      <xsl:value-of select="substring(Effective_Moment, 1, 10)"/>
      <xsl:text>,</xsl:text>
      <xsl:value-of select="Worker_Status/Status"/>
      <xsl:text>&#xA;</xsl:text>
    </xsl:for-each-group>
  </xsl:template>
</xsl:transform>

注意:你的源 XML 有一个不平衡的 peci:Worker 开始标签,我删除了它们.

Caution: Your source XML has one unbalanced peci:Worker opening tag, I deleted them.

注意:可以单独按生效日期进行分组,但我认为不是你想要的.如果您的输入包含多个对不同员工的有效变更,但在同一生效日期,那么输出将只包含来自该组的一条记录.这就是我使用复合键进行分组的原因,还包括员工 ID.

Note: It is possible to perform grouping solely by the effective date, but I think is not what you want. If your input contained a number of effective changes for different employees, but on the same effective date, then the output would have contained only one record from this group. This is why I performed grouping using a composite key, including also the employee ID.

这篇关于基于生效日期和顺序创建 xslt 转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆