2017-10-05 10 views
0

テンプレートを使用して、文字列 'REPORT_BLANK'をデフォルト値「」に置き換えようとしています。 'Status'属性(xsl出力内)で動作しているようですが、 'PayGroup' attirbuteのために、私は不要な要素から '& #x'文字とデータを含む予期せぬ出力を得ています。この初心者を助けてください。XSL出力に予期しない '&#x'が表示される

XMLソース:

<?xml version = '1.0' encoding = 'UTF-8'?> 
<DATA_DS> 
    <G_1> 
     <PAYROLL_ACTION_ID>5103</PAYROLL_ACTION_ID> 
     <G_2> 
      <FILE_FRAGMENT> 
       <PayrollInterface> 
        <REP_CATEGORY_NAME>HMLR ePayfact GIF Interface 1</REP_CATEGORY_NAME> 
        <parameters> 
         <RequestID>300000016822367</RequestID> 
         <FLOW_NAME>04102017-11:26</FLOW_NAME> 
         <LegislativeDataGroupID>300000001404188</LegislativeDataGroupID> 
         <EffectiveDate>2017-10-04</EffectiveDate> 
         <StartDate>2017-10-04</StartDate> 
         <ReportCategoryID>300000016773109</ReportCategoryID> 
         <action_parameter_group_id>300000000174069</action_parameter_group_id> 
         <ChangesOnly>N</ChangesOnly> 
         <PayrollName>300000001632050</PayrollName> 
         <PayrollPeriod/> 
         <SuppressZeroBalance/> 
        </parameters> 
        <InterfaceData> 
         <OBJECT_ACTION_ID>18527</OBJECT_ACTION_ID> 
         <Employee> 
          <Employee> 
           <EmployeeBasic> 
            <EmployeeNo>50120</EmployeeNo> 
           </EmployeeBasic> 
          </Employee> 
         </Employee> 
         <EELocation> 
          <EELocation_Employment> 
           <EELocation_Assignment_Data> 
            <EELocation_Assignment> 
             <EELocation_Rec> 
              <HRAssignmentID_Internal>300000016784341</HRAssignmentID_Internal> 
             </EELocation_Rec> 
            </EELocation_Assignment> 
           </EELocation_Assignment_Data> 
          </EELocation_Employment> 
         </EELocation> 
         <EEPSPayChange> 
          <EEPSPayChange_Employment> 
           <EEPSPayChange_Assignment_Data> 
            <EEPSPayChange_Assignment> 
             <GradeStepRateValue_Record/> 
             <EEPSPayChange_Rec> 
              <HRAssignmentID_Internal>300000016784341</HRAssignmentID_Internal> 
              <PersonLatestHireDate_Internal>2017-10-03T00:00:00.000Z</PersonLatestHireDate_Internal> 
              <EffectiveDate>2017-10-03T00:00:00.000Z</EffectiveDate> 
              <ChangeType>START</ChangeType> 
              <GradeId/> 
              <AssignmentCategory_Internal/> 
              <GradeSubCode>REPORT_BLANK</GradeSubCode> 
              <Salary_Internal/> 
              <Salary_2_Internal>TOBEDERIVED</Salary_2_Internal> 
              <AssignFullTimeHours_Internal>37</AssignFullTimeHours_Internal> 
              <MaxOTRateType>N</MaxOTRateType> 
              <FTE_Internal>1</FTE_Internal> 
              <PayGroupId>06</PayGroupId> 
              <PersonType_Internal>Permanent</PersonType_Internal> 
              <Classification>01</Classification> 
              <HoursPayable>37</HoursPayable> 
              <WorkingPatternId>501</WorkingPatternId> 
              <OSPSchemeNo>1</OSPSchemeNo> 
              <MilestoneDate_Internal>TOBEDERIVED</MilestoneDate_Internal> 
             </EEPSPayChange_Rec> 
            </EEPSPayChange_Assignment> 
           </EEPSPayChange_Assignment_Data> 
          </EEPSPayChange_Employment> 
         </EEPSPayChange> 
         <EEPSLocation> 
          <EEPSLocation_TermsDataGroup> 
           <EEPSLocation_TermsRecord> 
            <EEPSLocation_AssgnDataGroup> 
             <EEPSLocation_AssgnRecord> 
              <PersonType_Internal>Permanent</PersonType_Internal> 
              <PersonLatestHireDate_Internal>2017-10-03T00:00:00.000Z</PersonLatestHireDate_Internal> 
              <EffectiveDate>2017-10-03T00:00:00.000Z</EffectiveDate> 
              <DetachedDutyInd>N</DetachedDutyInd> 
              <LedgerHeading>LD</LedgerHeading> 
              <HRAssignmentID_Internal>300000016784341</HRAssignmentID_Internal> 
             </EEPSLocation_AssgnRecord> 
            </EEPSLocation_AssgnDataGroup> 
           </EEPSLocation_TermsRecord> 
          </EEPSLocation_TermsDataGroup> 
         </EEPSLocation> 
         <EEBankDetail/> 
         <EEPaymentElement/> 
        </InterfaceData> 
        <InterfaceData> 
         <OBJECT_ACTION_ID>18505</OBJECT_ACTION_ID> 
         <Employee> 
          <Employee> 
           <EmployeeBasic> 
            <EmployeeNo>50061</EmployeeNo> 
            <Status>REPORT_BLANK</Status> 
            <PensElig>Y</PensElig> 
           </EmployeeBasic> 
           <EmployeeBasic_DateMarriageCeased> 
            <PersonDetailsRecords> 
             <PersonDetails> 
              <PersonID_Internal>300000015958328</PersonID_Internal> 
              <DateMarriageCeased/> 
             </PersonDetails> 
            </PersonDetailsRecords> 
           </EmployeeBasic_DateMarriageCeased> 
           <EmployeeTermination> 
            <TerminationDetailsRecord> 
             <TerminationDetails> 
              <TerminationAction_Internal/> 
              <TerminationStatus_Internal>REPORT_BLANK</TerminationStatus_Internal> 
              <LeavingDate/> 
              <ReasonForLeaving/> 
              <PersonID_Internal>300000015958328</PersonID_Internal> 
             </TerminationDetails> 
            </TerminationDetailsRecord> 
           </EmployeeTermination> 
          </Employee> 
         </Employee> 
         <EELocation> 
          <EELocation_Employment> 
           <EELocation_Assignment_Data> 
            <EELocation_Assignment> 
             <EELocation_Rec> 
              <HRAssignmentID_Internal>300000015958405</HRAssignmentID_Internal> 
             </EELocation_Rec> 
            </EELocation_Assignment> 
           </EELocation_Assignment_Data> 
          </EELocation_Employment> 
          <EELocation_Employment> 
           <EELocation_Assignment_Data> 
            <EELocation_Assignment> 
             <EELocation_Rec> 
              <HRAssignmentID_Internal>300000016544638</HRAssignmentID_Internal> 
             </EELocation_Rec> 
            </EELocation_Assignment> 
           </EELocation_Assignment_Data> 
          </EELocation_Employment> 
         </EELocation> 
         <EEPSPayChange> 
          <EEPSPayChange_Employment> 
           <EEPSPayChange_Assignment_Data> 
            <EEPSPayChange_Assignment> 
             <GradeStepRateValue_Record> 
              <GradeStepRateValue> 
               <GradeStepRateValue_Record> 
                <AssgnID_Internal>300000015958405</AssgnID_Internal> 
                <GradeStepRateValue_Internal>49547</GradeStepRateValue_Internal> 
               </GradeStepRateValue_Record> 
              </GradeStepRateValue> 
             </GradeStepRateValue_Record> 
             <EEPSPayChange_Rec> 
              <HRAssignmentID_Internal>300000015958405</HRAssignmentID_Internal> 
              <PayGroupId>06</PayGroupId> 
             </EEPSPayChange_Rec> 
            </EEPSPayChange_Assignment> 
           </EEPSPayChange_Assignment_Data> 
          </EEPSPayChange_Employment> 
          <EEPSPayChange_Employment> 
           <EEPSPayChange_Assignment_Data> 
            <EEPSPayChange_Assignment> 
             <GradeStepRateValue_Record/> 
             <EEPSPayChange_Rec> 
              <PayGroupId>08</PayGroupId> 
             </EEPSPayChange_Rec> 
            </EEPSPayChange_Assignment> 
           </EEPSPayChange_Assignment_Data> 
          </EEPSPayChange_Employment> 
         </EEPSPayChange> 
         <EEPSLocation> 
          <EEPSLocation_TermsDataGroup> 
           <EEPSLocation_TermsRecord> 
            <EEPSLocation_AssgnDataGroup> 
             <EEPSLocation_AssgnRecord> 
              <PersonType_Internal>Permanent</PersonType_Internal> 
             </EEPSLocation_AssgnRecord> 
            </EEPSLocation_AssgnDataGroup> 
           </EEPSLocation_TermsRecord> 
          </EEPSLocation_TermsDataGroup> 
          <EEPSLocation_TermsDataGroup> 
           <EEPSLocation_TermsRecord> 
            <EEPSLocation_AssgnDataGroup> 
             <EEPSLocation_AssgnRecord> 
              <PersonType_Internal>Permanent</PersonType_Internal> 
             </EEPSLocation_AssgnRecord> 
            </EEPSLocation_AssgnDataGroup> 
           </EEPSLocation_TermsRecord> 
          </EEPSLocation_TermsDataGroup> 
         </EEPSLocation> 
         <EEBankDetail/> 
         <EEPaymentElement/> 
        </InterfaceData> 
        <InterfaceData> 
         <OBJECT_ACTION_ID>18511</OBJECT_ACTION_ID> 
         <Employee> 
          <Employee> 
           <EmployeeBasic> 
            <EmployeeNo>41356</EmployeeNo> 
            <EffectiveDate>2017-10-04T00:00:00.000Z</EffectiveDate> 
            <PensElig>Y</PensElig> 
           </EmployeeBasic> 
           <EmployeeBasic_DateMarriageCeased> 
            <PersonDetailsRecords> 
             <PersonDetails> 
              <PersonID_Internal>300000015238875</PersonID_Internal> 
              <DateMarriageCeased/> 
             </PersonDetails> 
            </PersonDetailsRecords> 
           </EmployeeBasic_DateMarriageCeased> 
           <EmployeeAddress/> 
           <EmployeeTermination> 
            <TerminationDetailsRecord> 
             <TerminationDetails> 
              <TerminationAction_Internal/> 
              <TerminationStatus_Internal>REPORT_BLANK</TerminationStatus_Internal> 
              <LeavingDate/> 
              <ReasonForLeaving/> 
              <PersonID_Internal>300000015238875</PersonID_Internal> 
             </TerminationDetails> 
            </TerminationDetailsRecord> 
           </EmployeeTermination> 
          </Employee> 
         </Employee> 
         <EELocation> 
          <EELocation_Employment> 
           <EELocation_Assignment_Data> 
            <EELocation_Assignment> 
             <EELocation_Rec> 
              <HRAssignmentID_Internal>300000015239345</HRAssignmentID_Internal> 
             </EELocation_Rec> 
            </EELocation_Assignment> 
           </EELocation_Assignment_Data> 
          </EELocation_Employment> 
         </EELocation> 
         <EEPSPayChange> 
          <EEPSPayChange_Employment> 
           <EEPSPayChange_Assignment_Data> 
            <EEPSPayChange_Assignment> 
             <GradeStepRateValue_Record/> 
             <EEPSPayChange_Rec> 
              <HRAssignmentID_Internal>300000015239345</HRAssignmentID_Internal> 
              <PayGroupId>REPORT_BLANK</PayGroupId> 
             </EEPSPayChange_Rec> 
            </EEPSPayChange_Assignment> 
           </EEPSPayChange_Assignment_Data> 
          </EEPSPayChange_Employment> 
         </EEPSPayChange> 
         <EEPSLocation> 
          <EEPSLocation_TermsDataGroup> 
           <EEPSLocation_TermsRecord> 
            <EEPSLocation_AssgnDataGroup> 
             <EEPSLocation_AssgnRecord> 
              <PersonType_Internal>Apprenticeship</PersonType_Internal> 
             </EEPSLocation_AssgnRecord> 
            </EEPSLocation_AssgnDataGroup> 
           </EEPSLocation_TermsRecord> 
          </EEPSLocation_TermsDataGroup> 
         </EEPSLocation> 
         <EEBankDetail/> 
         <EEPaymentElement/> 
        </InterfaceData> 
       </PayrollInterface> 
      </FILE_FRAGMENT> 
     </G_2> 
    </G_1> 
</DATA_DS> 

XSL:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> 

    <xsl:template match="/"> 
     <company> 
      <Data> 
       <Payroll> 
        <xsl:for-each-group select="//InterfaceData" group-by="OBJECT_ACTION_ID"> 

         <!-- Employee --> 
         <Employee> 
          <xsl:for-each select="current-group()//EmployeeBasic"> 
           <xsl:for-each select="./*"> 
            <xsl:call-template name="CGIelementToAttribute"> 
             <xsl:with-param name="myVarElementName" select="name(.)"/> 
             <xsl:with-param name="myVarElementValue" select="current()" 
             /> 
            </xsl:call-template> 
           </xsl:for-each> 
          </xsl:for-each> 

          <xsl:call-template name="CGIelementToAttribute"> 
           <xsl:with-param name="myVarElementName" select="'PayGroup'"/> 
           <xsl:with-param name="myVarElementValue" select="EEPSPayChange/EEPSPayChange_Employment[last()]/EEPSPayChange_Assignment_Data[1]/EEPSPayChange_Assignment[1]/EEPSPayChange_Rec[1]/PayGroupId[1]/text()"/> 
          </xsl:call-template> 

         </Employee> 

        </xsl:for-each-group> 
       </Payroll> 
      </Data> 
     </company> 
    </xsl:template> 

    <xsl:template name="CGIelementToAttribute"> 
     <xsl:param name="myVarElementName"/> 
     <xsl:param name="myVarElementValue"/> 

     <!-- if the element value contains 'BLANK' or the element name ends with 'Internal' it will not be output --> 
     <xsl:if 
      test="not(contains('|BLANK|', concat('|', $myVarElementValue, '|'))) and not(ends-with(name(), 'Internal')) and not(contains('|Salary|', concat('|', $myVarElementName, '|')))"> 
      <xsl:choose> 

       <!-- empty element --> 
       <xsl:when test="$myVarElementValue = ''"> 
        <xsl:attribute name="{$myVarElementName}"> 
         <xsl:value-of select="''"/> 
        </xsl:attribute> 
       </xsl:when> 

       <!-- output 'REPORT BLANK' as the attribute value --> 
       <xsl:when test="(contains('|REPORT_BLANK|', concat('|', $myVarElementValue, '|')))"> 
        <xsl:attribute name="{$myVarElementName}"> 
         <xsl:call-template name="string-replace-all"> 
          <xsl:with-param name="text" select="current()"/> 
          <xsl:with-param name="replace" select="'REPORT_BLANK'"/> 
          <xsl:with-param name="by" select="''"/> 
         </xsl:call-template> 
        </xsl:attribute> 
       </xsl:when> 

       <!-- format date --> 
       <xsl:when test="contains($myVarElementName, 'Date')"> 
        <xsl:call-template name="formatDate"> 
         <xsl:with-param name="myVarDateString" select="$myVarElementValue"/> 
         <xsl:with-param name="myVarDateName" select="$myVarElementName"/> 
        </xsl:call-template> 
       </xsl:when> 

       <!-- no transformation --> 
       <xsl:otherwise> 
        <xsl:attribute name="{$myVarElementName}"> 
         <xsl:value-of select="$myVarElementValue"/> 
        </xsl:attribute> 
       </xsl:otherwise> 

      </xsl:choose> 
     </xsl:if> 

    </xsl:template> 

    <xsl:template name="formatDate"> 

     <!-- CGIformatDate: converts dateto CGI format from CCYY-MM-DDThh:mm:ss:mm[Z] to dd/mm/ccyy --> 
     <xsl:param name="myVarDateString"/> 
     <xsl:param name="myVarDateName"/> 

     <xsl:attribute name="{$myVarDateName}"> 
      <xsl:value-of select="concat(substring($myVarDateString, 9, 2), '/', substring($myVarDateString, 6, 2), '/', substring($myVarDateString, 1, 4))"/> 
     </xsl:attribute> 
    </xsl:template> 


    <xsl:template name="string-replace-all"> 
     <xsl:param name="text"/> 
     <xsl:param name="replace"/> 
     <xsl:param name="by"/> 
     <xsl:variable name="str1"> 
      <xsl:call-template name="string-replace"> 
       <xsl:with-param name="text" select="$text"/> 
       <xsl:with-param name="replace" select="$replace"/> 
       <xsl:with-param name="by" select="$by"/> 
      </xsl:call-template> 
     </xsl:variable> 
     <xsl:variable name="str2"> 
      <!-- 2nd... clean up --> 
      <xsl:call-template name="string-replace"> 
       <xsl:with-param name="text" select="$str1"/> 
       <xsl:with-param name="replace" select="$replace"/> 
       <xsl:with-param name="by" select="$by"/> 
      </xsl:call-template> 
     </xsl:variable> 
     <xsl:variable name="str3"> 
      <xsl:choose> 
       <xsl:when 
        test="substring($str2, string-length($str2) - string-length($by), string-length($str2)) = concat($by, ' ')"> 
        <xsl:value-of 
         select="substring($str2, 1, string-length($str2) - string-length($by) - 1)" 
        /> 
       </xsl:when> 
       <xsl:otherwise> 
        <xsl:value-of select="$str2"/> 
       </xsl:otherwise> 
      </xsl:choose> 
     </xsl:variable> 
     <xsl:choose> 
      <xsl:when test="substring($str3, 1, string-length($by) + 1) = concat($by, ' ')"> 
       <xsl:value-of select="substring-after($str3, concat($by, ' '))"/> 
      </xsl:when> 
      <xsl:otherwise> 
       <xsl:value-of select="$str3"/> 
      </xsl:otherwise> 
     </xsl:choose> 
    </xsl:template> 

    <xsl:template name="string-replace"> 
     <xsl:param name="text"/> 
     <xsl:param name="replace"/> 
     <xsl:param name="by"/> 
     <xsl:choose> 
      <xsl:when test="contains($text, $replace)"> 
       <xsl:value-of select="substring-before($text, $replace)"/> 
       <xsl:value-of select="$by"/> 
       <xsl:call-template name="string-replace"> 
        <xsl:with-param name="text" select="substring-after($text, $replace)"/> 
        <xsl:with-param name="replace" select="$replace"/> 
        <xsl:with-param name="by" select="$by"/> 
       </xsl:call-template> 
      </xsl:when> 
      <xsl:otherwise> 
       <xsl:value-of select="$text"/> 
      </xsl:otherwise> 
     </xsl:choose> 
    </xsl:template> 

</xsl:stylesheet> 

XSL出力:何が起こっている

<?xml version="1.0" encoding="UTF-8"?> 
<company> 
    <Data> 
     <Payroll> 
      <Employee EmployeeNo="50120" PayGroup="06"></Employee> 
      <Employee EmployeeNo="50061" Status="TOBEDERIVED" PensElig="Y" PayGroup="08"></Employee> 
      <Employee EmployeeNo="41356" EffectiveDate="04/10/2017" PensElig="Y" 
       PayGroup="&#xA;      18511&#xA;      &#xA;       &#xA;        &#xA;         41356&#xA;         2017-10-04T00:00:00.000Z&#xA;         Y&#xA;        &#xA;        &#xA;         &#xA;          &#xA;           300000015238875&#xA;           &#xA;          &#xA;         &#xA;        &#xA;        &#xA;        &#xA;         &#xA;          &#xA;           &#xA;           &#xA;           &#xA;           &#xA;           300000015238875&#xA;          &#xA;         &#xA;        &#xA;       &#xA;      &#xA;      &#xA;       &#xA;        &#xA;         &#xA;          &#xA;           300000015239345&#xA;          &#xA;         &#xA;        &#xA;       &#xA;      &#xA;      &#xA;       &#xA;        &#xA;         &#xA;          &#xA;          &#xA;           300000015239345&#xA;           &#xA;          &#xA;         &#xA;        &#xA;       &#xA;      &#xA;      &#xA;       &#xA;        &#xA;         &#xA;          &#xA;           Apprenticeship&#xA;          &#xA;         &#xA;        &#xA;       &#xA;      &#xA;      &#xA;      &#xA;     " 
      ></Employee> 
     </Payroll> 
    </Data> 
</company> 
+0

これは '' REPORT_BLANK''という値を持つ 'CGIelementToAttribute'を呼び出した結果です...' string-replace-all'関数をデバッグする必要があります –

+0

私は全く新しいです、デバッグするにはどうすればよいですか?私は酸素XML開発者を持って、良いリンク/ビデオ私はXSLをデバッグすることができますか? – murfy92

+0

https://www.freeformatter.com/xsl-transformer.html#ad-output最も簡単なxmlを作成して、問題のある部分だけを取得してから修正するまで、xsltで関連する部分を削除することができますそして元のxsltにマージする –

答えて

0

InterfaceDataのすべてtext()子孫が自分の属性に出力されているです。これには、空白と改行が含まれます。

xsl:stylesheetの子として<xsl:strip-space elements="*"/>を追加すると、スペースとともに改行の16進数の参照が削除されていることがわかります。しかし、値はまだ間違っているように見えます。

CGIelementToAttributeという名前のテンプレートにstring-replace-allというテンプレートを使用しているため、current()が使用されていると思われます。

この変更してみてください。これに

<!-- output 'REPORT BLANK' as the attribute value --> 
<xsl:when test="(contains('|REPORT_BLANK|', concat('|', $myVarElementValue, '|')))"> 
    <xsl:attribute name="{$myVarElementName}"> 
    <xsl:call-template name="string-replace-all"> 
     <xsl:with-param name="text" select="current()"/>    <!-- THIS LINE --> 
     <xsl:with-param name="replace" select="'REPORT_BLANK'"/> 
     <xsl:with-param name="by" select="''"/> 
    </xsl:call-template> 
    </xsl:attribute> 
</xsl:when> 

を:

<!-- output 'REPORT BLANK' as the attribute value --> 
<xsl:when test="(contains('|REPORT_BLANK|', concat('|', $myVarElementValue, '|')))"> 
    <xsl:attribute name="{$myVarElementName}"> 
    <xsl:call-template name="string-replace-all"> 
     <xsl:with-param name="text" select="$myVarElementValue"/> <!-- THIS LINE --> 
     <xsl:with-param name="replace" select="'REPORT_BLANK'"/> 
     <xsl:with-param name="by" select="''"/> 
    </xsl:call-template> 
    </xsl:attribute> 
</xsl:when> 

ます。また、交換する必要があるかもしれません:

<xsl:with-param name="by" select="''"/> 

で:

<xsl:with-param name="by" select="'REPORT BLANK'"/> 

それ以外の場合、属性値は空白になります。これはxsl:whenより前のコメントに基づいています。 (<!-- output 'REPORT BLANK' as the attribute value -->

また、実際にXSLT 2.0プロセッサを使用している場合は、名前付きテンプレートの代わりにreplace()関数を使用するだけでいいのですか?

関連する問題