问题
I have a payroll XML file that contains a child element(pay_component_code) for every line item row. I'm provided with a mapping document that contains translation between current codes and future codes, either 1:1 or M:1. The requirement is to convert the xml to pipe delimited text file and also aggregate the amount based on a grouping of person number, effective date and pay component code (future state). The xslt I have seems to work fine for a sample population but however, when I ran the program for another group, it errors with following error:
A sequence of more than one item is not allowed as the first argument of concat() (<payCode/>, <payCode/>) Line: 1786 Column: 11
I see it happens when the node in context has more than one child element. Can someone explain what the issue might be? Oxygen editor has not been very helpful as it highlights the entire xml, which is too long to analyse the root issue.
Sample xml:
<?xml version='1.0' encoding='UTF-8'?>
<wd:Report_Data xmlns:wd="urn:com.workday.report/ERP_PAY_CR_PAYROLL_BALANCES_LINE_AMT">
<wd:Report_Entry>
<wd:Country_Code>US</wd:Country_Code>
<wd:Entity_Name>BalanceInitialization</wd:Entity_Name>
<wd:Legislative_Data_Group_Name>US Legislative Data Group</wd:Legislative_Data_Group_Name>
<wd:Legal_Entity_Name wd:Descriptor="SRMH">
<wd:ID wd:type="WID">66b06c2b4ec001df7d2d7875ea020e52</wd:ID>
<wd:ID wd:type="Organization_Reference_ID">G123</wd:ID>
<wd:ID wd:type="Company_Reference_ID">G123</wd:ID>
</wd:Legal_Entity_Name>
<wd:Person_Number>2110013</wd:Person_Number>
<wd:Effective_Date>2020-01-01</wd:Effective_Date>
<wd:Period>2020-Q1</wd:Period>
<wd:Dimension>Assignment Tax Unit Quarter to Date</wd:Dimension>
<wd:Pay_Component_Name>102 Regular - Hourly</wd:Pay_Component_Name>
<wd:Pay_Component_Code>102</wd:Pay_Component_Code>
<wd:Number>3143.28</wd:Number>
<wd:Payroll wd:Descriptor="PSJH Biweekly B">
<wd:ID wd:type="WID">2d405a8ea1ea01265d95c04def2d96c7</wd:ID>
<wd:ID wd:type="Evaluate_Expression_Band_Related_Content_Reference_ID"
>EVALUATE_EXPRESSION_BAND_CALCULATED_FIELD_RELATED_CONTENT-6-2d405a8ea1ea01265d95c04def2d96c7</wd:ID>
</wd:Payroll>
<wd:Tax_Reporting_Unit>SJHNC, LLC</wd:Tax_Reporting_Unit>
<wd:Company_ID>G123</wd:Company_ID>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Country_Code>US</wd:Country_Code>
<wd:Entity_Name>BalanceInitialization</wd:Entity_Name>
<wd:Legislative_Data_Group_Name>US Legislative Data Group</wd:Legislative_Data_Group_Name>
<wd:Legal_Entity_Name wd:Descriptor="SRMH">
<wd:ID wd:type="WID">66b06c2b4ec001df7d2d7875ea020e52</wd:ID>
<wd:ID wd:type="Organization_Reference_ID">G123</wd:ID>
<wd:ID wd:type="Company_Reference_ID">G123</wd:ID>
</wd:Legal_Entity_Name>
<wd:Person_Number>2110013</wd:Person_Number>
<wd:Effective_Date>2020-01-01</wd:Effective_Date>
<wd:Period>2020-Q1</wd:Period>
<wd:Dimension>Assignment Tax Unit Quarter to Date</wd:Dimension>
<wd:Pay_Component_Name>123 Overtime - OT Prem</wd:Pay_Component_Name>
<wd:Pay_Component_Code>123</wd:Pay_Component_Code>
<wd:Number>185.31</wd:Number>
<wd:Payroll wd:Descriptor="PSJH Biweekly B">
<wd:ID wd:type="WID">2d405a8ea1ea01265d95c04def2d96c7</wd:ID>
<wd:ID wd:type="Evaluate_Expression_Band_Related_Content_Reference_ID"
>EVALUATE_EXPRESSION_BAND_CALCULATED_FIELD_RELATED_CONTENT-6-2d405a8ea1ea01265d95c04def2d96c7</wd:ID>
</wd:Payroll>
<wd:Tax_Reporting_Unit>SJHNC, LLC</wd:Tax_Reporting_Unit>
<wd:Company_ID>G123</wd:Company_ID>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Country_Code>US</wd:Country_Code>
<wd:Entity_Name>BalanceInitialization</wd:Entity_Name>
<wd:Legislative_Data_Group_Name>US Legislative Data Group</wd:Legislative_Data_Group_Name>
<wd:Legal_Entity_Name wd:Descriptor="SRMH">
<wd:ID wd:type="WID">66b06c2b4ec001df7d2d7875ea020e52</wd:ID>
<wd:ID wd:type="Organization_Reference_ID">G123</wd:ID>
<wd:ID wd:type="Company_Reference_ID">G123</wd:ID>
</wd:Legal_Entity_Name>
<wd:Person_Number>2110013</wd:Person_Number>
<wd:Effective_Date>2020-01-01</wd:Effective_Date>
<wd:Period>2020-Q1</wd:Period>
<wd:Dimension>Assignment Tax Unit Quarter to Date</wd:Dimension>
<wd:Pay_Component_Name>126 Overtime - OT Base</wd:Pay_Component_Name>
<wd:Pay_Component_Code>126</wd:Pay_Component_Code>
<wd:Number>370.61</wd:Number>
<wd:Payroll wd:Descriptor="PSJH Biweekly B">
<wd:ID wd:type="WID">2d405a8ea1ea01265d95c04def2d96c7</wd:ID>
<wd:ID wd:type="Evaluate_Expression_Band_Related_Content_Reference_ID"
>EVALUATE_EXPRESSION_BAND_CALCULATED_FIELD_RELATED_CONTENT-6-2d405a8ea1ea01265d95c04def2d96c7</wd:ID>
</wd:Payroll>
<wd:Tax_Reporting_Unit>SJHNC, LLC</wd:Tax_Reporting_Unit>
<wd:Company_ID>G123</wd:Company_ID>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Country_Code>US</wd:Country_Code>
<wd:Entity_Name>BalanceInitialization</wd:Entity_Name>
<wd:Legislative_Data_Group_Name>US Legislative Data Group</wd:Legislative_Data_Group_Name>
<wd:Legal_Entity_Name wd:Descriptor="SRMH">
<wd:ID wd:type="WID">66b06c2b4ec001df7d2d7875ea020e52</wd:ID>
<wd:ID wd:type="Organization_Reference_ID">G123</wd:ID>
<wd:ID wd:type="Company_Reference_ID">G123</wd:ID>
</wd:Legal_Entity_Name>
<wd:Person_Number>2110013</wd:Person_Number>
<wd:Effective_Date>2020-01-01</wd:Effective_Date>
<wd:Period>2020-Q1</wd:Period>
<wd:Dimension>Assignment Tax Unit Quarter to Date</wd:Dimension>
<wd:Pay_Component_Name>420 Time Off - PTO</wd:Pay_Component_Name>
<wd:Pay_Component_Code>420</wd:Pay_Component_Code>
<wd:Number>1623.96</wd:Number>
<wd:Payroll wd:Descriptor="PSJH Biweekly B">
<wd:ID wd:type="WID">2d405a8ea1ea01265d95c04def2d96c7</wd:ID>
<wd:ID wd:type="Evaluate_Expression_Band_Related_Content_Reference_ID"
>EVALUATE_EXPRESSION_BAND_CALCULATED_FIELD_RELATED_CONTENT-6-2d405a8ea1ea01265d95c04def2d96c7</wd:ID>
</wd:Payroll>
<wd:Tax_Reporting_Unit>SJHNC, LLC</wd:Tax_Reporting_Unit>
<wd:Company_ID>G123</wd:Company_ID>
</wd:Report_Entry>
XSLT:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wd="urn:com.workday.report/ERP_PAY_CR_PAYROLL_BALANCES_LINE_AMT">
<xsl:output method="text"/>
<xsl:variable name="linefeed" select="'
'"/>
<xsl:variable name="pipe" select="'|'"/>
<xsl:param name="quote">"</xsl:param>
<xsl:variable name="payCodes">
<payCode name="Admin Leave Paid">
<legacyCode>400</legacyCode>
<legacyCode>432</legacyCode>
<payCode name="Regular">
<legacyCode>101</legacyCode>
<legacyCode>102</legacyCode>
<legacyCode>103</legacyCode>
<legacyCode>112</legacyCode>
<legacyCode>800</legacyCode>
<legacyCode>964</legacyCode>
</payCode>
<payCode name="Overtime Weekly">
<legacyCode>126</legacyCode>
</payCode>
<payCode name="Overtime Weekly FLSA">
<legacyCode>123</legacyCode>
</payCode>
</payCode>
<payCode name="Bereavement">
<legacyCode>410</legacyCode>
<legacyCode>436</legacyCode>
</payCode>
<payCode name="Break Penalty">
<legacyCode>777</legacyCode>
</payCode>
<payCode name="PTO Donation">
<legacyCode>413</legacyCode>
<legacyCode>420</legacyCode>
<legacyCode>422</legacyCode>
</payCode>
<payCode name="CA Healthy Family PTO">
<legacyCode>496</legacyCode>
<legacyCode>497</legacyCode>
<legacyCode>498</legacyCode>
<legacyCode>499</legacyCode>
</payCode>
<payCode name="Callback 1 5">
<legacyCode>153</legacyCode>
</payCode>
</xsl:variable>
<xsl:key name="paycode" match="payCode" use="legacyCode" />
<xsl:template match="/wd:Report_Data">
<!-- <xsl:variable name="common">
<xsl:value-of select="wd:Report_Entry/wd:Legal_Entity_Name/@wd:Descriptor"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="wd:Report_Entry/wd:Person_Number"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="wd:Report_Entry/wd:Calendar_Quarter/@wd:Descriptor"/>
<xsl:text>|</xsl:text>
</xsl:variable> -->
<!-- HEADER LINE 1-->
<xsl:text>Country Code|Entity Name|Legislative Data Group Name|Legal Entity Name|Person Number|Effective As Of Date|Assignment Number|Value|Upload Date|Balance|Dimension|Payroll Relationship Number|Term Number|Assignment Number|Legal Employer|Payroll|Area One|Area Two|Area Three|Area Four|Third Party Payee|Time Definition|Calculation Breakdown|Balance Date|Tax Reporting Unit|Run Type|Context One|Context One Value|Context Two|Context Two Value|Context Three|Context Three Value|Context Four|Context Four Value|Context Five|Context Five Value|Context Six|Context Six Value
</xsl:text>
<!-- HEADER LINE 2-->
<xsl:text>COUNTRY_CODE|ENTITY_NAME|LEGISLATIVE_DATA_GROUP|LEGAL_ENTITY_NAME|PERSON_NUMBER|EFFECTIVE_DATE|ASSIGNMENT_NUMBER|POSITION2|POSITION3|POSITION4|POSITION5|POSITION6|POSITION7|POSITION8|POSITION9|POSITION10|POSITION11|POSITION12|POSITION13|POSITION14|POSITION15|POSITION16|POSITION17|POSITION18|POSITION19|POSITION20|POSITION21|POSITION22|POSITION23|POSITION24|POSITION25|POSITION26|POSITION27|POSITION28|POSITION29|POSITION30|POSITION31|POSITION32
</xsl:text>
<!-- HEADER LINE 3 -->
<xsl:text>VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|DATE|VARCHAR2|NUMBER|DATE|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|DATE|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2|VARCHAR2
</xsl:text>
<!-- DATA -->
<xsl:for-each-group select="wd:Report_Entry" group-by="concat(key('paycode', wd:Pay_Component_Code, $payCodes),wd:Person_Number,wd:Effective_Date)">
<xsl:if test="exists(key('paycode', wd:Pay_Component_Code, $payCodes)/@name)">
<xsl:value-of select="wd:Country_Code"/>
<xsl:value-of select="$pipe"/>
<xsl:value-of select="wd:Entity_Name"/>
<xsl:value-of select="$pipe"/>
<xsl:value-of select="wd:Legislative_Data_Group_Name"/>
<xsl:value-of select="$pipe"/>
<xsl:value-of select="wd:Legal_Entity_Name/@wd:Descriptor"/>
<xsl:value-of select="$pipe"/>
<xsl:value-of select="wd:Person_Number"/>
<xsl:value-of select="$pipe"/>
<xsl:value-of select="wd:Effective_Date"/>
<xsl:value-of select="$pipe"/>
<!-- Assginment Number Place Holder -->
<xsl:text>|</xsl:text>
<xsl:value-of select="format-number(sum(current-group()/wd:Number),'#.00')"/>
<xsl:value-of select="$pipe"/>
<!-- Upload Date Place Holder -->
<xsl:value-of select="wd:Effective_Date"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="key('paycode', wd:Pay_Component_Code, $payCodes)/@name"/>
<xsl:value-of select="$pipe"/>
<!-- Dimension
<xsl:choose>
<xsl:when test="exists(wd:Earning)">
<xsl:value-of select="concat('Assignment Tax Unit',' ',substring-before(wd:Dimension/@wd:Descriptor,' 20'))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('Relationship Tax',' ',substring-before(wd:Dimension/@wd:Descriptor,' 20'))"/>
</xsl:otherwise>
</xsl:choose> -->
<xsl:value-of select="wd:Dimension"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="wd:Person_Number"/>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:value-of select="wd:Payroll/@wd:Descriptor"/>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<!-- Balance Date Place Holder -->
<xsl:value-of select="wd:Effective_Date"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="wd:Tax_Reporting_Unit"/>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
回答1:
I don't see a line 1786 in your stylesheet, but assuming that the problem is with
group-by="concat(key('paycode', wd:Pay_Component_Code, $payCodes),
wd:Person_Number, wd:Effective_Date)">
it's complaining about the first argument to concat(), saying that it contains a sequence of two payCode
elements. But even if it only selected one, this code would be questionable, because the element selected by the key() function would be atomized to get its string value, and the string value of a payCode
element isn't anything very meaningful. Perhaps it should be key(...)/@name
?
The problem seems to be with your data, not with your code; or rather, it's with the assumptions your code is making about your data, in particular uniqueness of values. I would therefore suggest that the solution lies in validation; define your data more precisely, e.g. with an XSD schema, and validate it before you apply the transformation. Alternatively, you can do a lot of validation with custom XSLT code.
来源:https://stackoverflow.com/questions/61490430/xslt-help-create-a-varibale-in-xslt-to-store-cross-reference-mapping-and-group