如何调整RTF模板将XML员工薪资数据按列格式展示?
问题描述
现有如下XML员工薪资数据:
<EMPLOYEE_INFORMATION_REC> <PERSON_NUMBER>31</PERSON_NUMBER> <Payroll_Relationship_Number>531</Payroll_Relationship_Number> <Payroll_ID>322623279</Payroll_ID> <PersonID>305634180</PersonID> <Payroll> <PERSONAL_PAYMENTS> <Payroll_Relationship_Rec> <Payroll_Relationship_Action_ID>326491</Payroll_Relationship_Action_ID> <Payroll_Interface_Effective_Date>2023-05-25T00:00:00.000Z</Payroll_Interface_Effective_Date> <Payroll_Interface_Base_Run_Type_Name>Regular Normal</Payroll_Interface_Base_Run_Type_Name> <Tax_Reporting_Unit>Saskatchewan Workers' Compensation Board</Tax_Reporting_Unit> <Action_Type>Q</Action_Type> <Run_Results> <Run_Results_Rec> <Input_Values_Base_Name>Hours</Input_Values_Base_Name> <Run_Result_Value>2.45</Run_Result_Value> <Base_Element_Name>Overtime 2x Result</Base_Element_Name> <Start_date>2023-05-15</Start_date> <End_date>2023-05-15</End_date> <Run_Result_ID>1530959</Run_Result_ID> <Primary_Classification_Name>Standard Earnings</Primary_Classification_Name> <PERSONID>300000015630330</PERSONID> </Run_Results_Rec> </Run_Results> <Run_Results> <Run_Results_Rec> <Input_Values_Base_Name>Hours</Input_Values_Base_Name> <Run_Result_Value>4.45</Run_Result_Value> <Base_Element_Name>Overtime 2x Result</Base_Element_Name> <Start_date>2023-05-17</Start_date> <End_date>2023-05-17</End_date> <Run_Result_ID>1530949</Run_Result_ID> <Primary_Classification_Name>Standard Earnings</Primary_Classification_Name> <PERSONID>300000015630330</PERSONID> </Run_Results_Rec> </Run_Results> </Payroll_Relationship_Rec> </PERSONAL_PAYMENTS> </Payroll> </EMPLOYEE_INFORMATION_REC>
需求是在RTF模板中,将Input_Values_Base_Name、Run_Result_Value、Base_Element_Name等字段以列而非行的形式展示。当前使用的RTF模板代码如下:
Person_number Input_Values_Base_Name Base_Element_Name <?for-each:EMPLOYEE_INFORMATION_REC?> <PERSON_NUMBER> <Input_Values_Base_Name> <Base_Element_Name> <?end for-each?>
期望实现如下表格展示效果:
| PERSON_NUMBER | Input_values_base_name | Base_Element_Name | Start_date |
|---|---|---|---|
| 31 | Hours | Overtime Result | 2023-05-17 |
| 31 | Hours | Value Result | 2023-05-15 |
请问应如何调整该RTF模板以满足上述需求?
调整方案
当前模板仅遍历了外层的EMPLOYEE_INFORMATION_REC节点,但薪资明细数据嵌套在Payroll/PERSONAL_PAYMENTS/Payroll_Relationship_Rec/Run_Results/Run_Results_Rec路径下,必须遍历最内层的明细节点才能生成多行数据。
正确的RTF模板代码如下(需在Word中插入表格后添加字段和循环指令):
<table> <tr> <th style="text-align:left">PERSON_NUMBER</th> <th style="text-align:center">Input_values_base_name</th> <th style="text-align:right">Base_Element_Name</th> <th style="text-align:right">Start_date</th> </tr> <?for-each:EMPLOYEE_INFORMATION_REC?> <?for-each:Payroll/PERSONAL_PAYMENTS/Payroll_Relationship_Rec?> <?for-each:Run_Results/Run_Results_Rec?> <tr> <td style="text-align:left"><?PERSON_NUMBER?></td> <td style="text-align:center"><?Input_Values_Base_Name?></td> <td style="text-align:right"><?Base_Element_Name?></td> <td style="text-align:right"><?Start_date?></td> </tr> <?end for-each?> <?end for-each?> <?end for-each?> </table>
关键说明:
- 层级遍历:逐层遍历到最内层的
Run_Results_Rec节点,每个节点对应表格的一行数据 - 字段作用域:在明细循环内可直接引用外层的
PERSON_NUMBER,因为处于外层循环的作用域内 - 格式设置:通过
style属性或Word自带的表格格式设置,可实现表头和内容的对齐要求
内容的提问来源于stack exchange,提问作者SSA_Tech124
相关产品推荐
相关产品推荐

