XSLT 帮助 - 在 XSLT 中创建变量以存储交叉引用映射并基于该映射对输入元素进行分组 [英] XSLT Help - Create a varibale in XSLT to store cross reference mapping and group input elements based on that mapping

查看:13
本文介绍了XSLT 帮助 - 在 XSLT 中创建变量以存储交叉引用映射并基于该映射对输入元素进行分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工资单 XML 文件,其中包含每个行项目行的子元素 (pay_component_code).我得到了一个映射文档,其中包含当前代码和未来代码(1:1 或 M:1)之间的转换.要求是将 xml 转换为管道分隔的文本文件,并根据人员编号、生效日期和支付组件代码(未来状态)的分组汇总金额.我拥有的 xslt 似乎适用于样本群体,但是,当我为另一组运行该程序时,它出现以下错误:concat() 的第一个参数不允许有多个项目的序列(, ) Line: 1786 Column: 11我看到当上下文中的节点有多个子元素时会发生这种情况.有人可以解释可能是什么问题吗?Oxygen 编辑器不是很有用,因为它突出显示了整个 xml,太长而无法分析根本问题.

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.

示例 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="'&#xD;&#xA;'"/>
    <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&#xD;&#xA;</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&#xD;&#xA;</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&#xD;&#xA;</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>&#xD;&#xA;</xsl:text>
                </xsl:if>
            </xsl:for-each-group>
    </xsl:template>

</xsl:stylesheet>

推荐答案

我在您的样式表中没有看到第 1786 行,但假设问题出在

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)">

它抱怨 concat() 的第一个参数,说它包含两个 payCode 元素的序列.但是即使只选了一个,这段代码也是有问题的,因为key()函数选中的元素会被原子化得到它的字符串值,而一个payCode元素的字符串值是't 任何非常有意义的事情.也许它应该是 key(...)/@name?

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?

问题似乎出在您的数据上,而不是出在您的代码上;或者更确切地说,这是您的代码对数据做出的假设,特别是值的唯一性.因此,我建议解决方案在于验证;更精确地定义您的数据,例如使用 XSD 架构,并在应用转换之前对其进行验证.或者,您可以使用自定义 XSLT 代码进行大量验证.

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.

这篇关于XSLT 帮助 - 在 XSLT 中创建变量以存储交叉引用映射并基于该映射对输入元素进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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