0

我有两个阶段文件,我必须将文件 1 中的 Job_Title 与文件 2 的 JOB_NAME 进行比较,我必须显示文件 1 中唯一的 Job_Title 值。我的代码按预期工作

文件 1:

'

<ReadResponse xmlns="http://xmlns.oracle.com/cloud/adapter/stagefile/ReadFilteredInputFile_REQUEST/types">
  <Records xmlns="http://TargetNamespace.com/fileReference/ReadFilteredInputFile">
    <Record>
      <Last_Name>Abbassi</Last_Name>
      <First_Name>Bob</First_Name>
      <Work_Contact_Work_Email>babbassi@xyz.com</Work_Contact_Work_Email>
      <Hire_Date>6/25/2012</Hire_Date>
      <Job_Title_Description>ASSOCIATE DIRECTOR</Job_Title_Description>
      <Job_Title_Code>ADIR</Job_Title_Code>
      <Home_Department_Description>Finance</Home_Department_Description>
      <Home_Department>121</Home_Department>
      <Rehire_Date></Rehire_Date>
      <Termination_Date></Termination_Date>
      <Position_ID>DXM001019</Position_ID>
      <Position_Status>Active</Position_Status>
      <Reports_To_Position_ID>DXM001077</Reports_To_Position_ID>
      <Reports_To_Name>Lee, Todd</Reports_To_Name>
      <This_is_a_Management_position>No</This_is_a_Management_position>
      <Job_Title>Associate Director, FP&amp;A</Job_Title>
    </Record>
    <Record>
      <Last_Name>Abejuela</Last_Name>
      <First_Name>Jowdy</First_Name>
      <Work_Contact_Work_Email>jabejuela@xyz.com</Work_Contact_Work_Email>
      <Hire_Date>12/9/2019</Hire_Date>
      <Job_Title_Description>SENIOR MANAGER</Job_Title_Description>
      <Job_Title_Code>SRMG</Job_Title_Code>
      <Home_Department_Description>Quality General</Home_Department_Description>
      <Home_Department>461</Home_Department>
      <Rehire_Date></Rehire_Date>
      <Termination_Date></Termination_Date>
      <Position_ID>DXM001514</Position_ID>
      <Position_Status>Active</Position_Status>
      <Reports_To_Position_ID>DXM001629</Reports_To_Position_ID>
      <Reports_To_Name>Golden, Kihlon</Reports_To_Name>
      <This_is_a_Management_position>No</This_is_a_Management_position>
      <Job_Title>Senior Manager, QA</Job_Title>
    </Record>
    <Record>
      <Last_Name>Acosta</Last_Name>
      <First_Name>Andrea</First_Name>
      <Work_Contact_Work_Email>aacosta@xyz.com</Work_Contact_Work_Email>
      <Hire_Date>5/18/2020</Hire_Date>
      <Job_Title_Description>RESEARCH ASSOCIATE</Job_Title_Description>
      <Job_Title_Code>RA</Job_Title_Code>
      <Home_Department_Description>Analytical</Home_Department_Description>
      <Home_Department>442</Home_Department>
      <Rehire_Date></Rehire_Date>
      <Termination_Date></Termination_Date>
      <Position_ID>DXM001536</Position_ID>
      <Position_Status>Active</Position_Status>
      <Reports_To_Position_ID>DXM001026</Reports_To_Position_ID>
      <Reports_To_Name>Kuehne, Henriette</Reports_To_Name>
      <This_is_a_Management_position>No</This_is_a_Management_position>
      <Job_Title>Research Associate</Job_Title>
    </Record>
  </Records>
</ReadResponse>

'

文件 2:'

<ReadResponse xmlns="http://xmlns.oracle.com/cloud/adapter/stagefile/ReadDecodedOTBIJobsResponse_REQUEST/types">
  <JobSet xmlns="http://TargetNamespace.com/fileReference/ReadDecodedOTBIJobsResponse">
    <Job>
      <JOB_ID>300000004123258</JOB_ID>
      <JOB_CODE>0002</JOB_CODE>
      <JOB_NAME>Senior Manager, QA</JOB_NAME>
    </Job>
    <Job>
      <JOB_ID>300000004123195</JOB_ID>
      <JOB_CODE>0001</JOB_CODE>
      <JOB_NAME>Associate Director, FP&amp;A</JOB_NAME>
    </Job>
  </JobSet>
</ReadResponse>

'预期输出:'

<JobSet>
    <Job>
      <Job_Title>Research Associate</JobTitle>
    </Job>
  </JobSet>

'

我的代码:

<ns50:NewJobSet>
<xsl:for-each select="$ReadFilteredInputFile/nsmpr8:ReadResponse/nsmpr3:Records/nsmpr3:Record">
<xsl:variable name="jobTitle" select="nsmpr3:Job_Title"/>
<xsl:for-each select="$ReadDecodedOTBIJobsResponse/nsmpr7:ReadResponse/ns37:JobSet/ns37:Job">
<xsl:variable name="jobName" select="ns37:JOB_NAME"/>
<xsl:choose>
<xsl:when test="ns37:JOB_NAME = $jobTitle"/>
<xsl:otherwise>
<ns50:NewJob>
<ns50:Job_Title>
<xsl:value-of select="$jobName"/>
</ns50:Job_Title>
</ns50:NewJob>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</ns50:NewJobSet>

如果两个文件之间有任何匹配记录,我的代码将返回重复项,有人可以帮忙解决这个问题吗?

4

1 回答 1

0

我会用钥匙

<xsl:key name="jobs" match="Job" use="JOB_NAME" xpath-default-namespace="http://TargetNamespace.com/fileReference/ReadDecodedOTBIJobsResponse"/>

然后检查例如

  <xsl:template match="Record/Job_Title[not(key('jobs', ., $jobs))]" xpath-default-namespace="http://TargetNamespace.com/fileReference/ReadFilteredInputFile">
    <Job_Title>
      <xsl:value-of select="."/>
    </Job_Title>
  </xsl:template>

$jobs保存第二个文档的变量在哪里。

以及在第二个文件中引用的那些元素的空模板,例如<xsl:template match="Record/Job_Title[key('jobs', ., $jobs)]" xpath-default-namespace="http://TargetNamespace.com/fileReference/ReadFilteredInputFile"/>

于 2022-02-08T09:42:45.730 回答