Xml 为每个语句检索上一个变量
我到处都找过了,已经使用XSLT代码好几天了,但我就是搞不懂这个。我会尽力解释,因为这是一个复杂的问题。文件必须按科目和部门汇总,然后有一个抵销行按以下输出中显示的部门汇总 wd:U代码='FLSA-01'的wd:Department不正确。wd:Earning_Code='FLSA-01'交易金额应绑定回wd:Earning_Code='OT'。问题是加班收入代码上可能有多个部门 我必须将FLSA总收入和加班收入总额除以职位,然后除以加班总小时数除以职位。然后,我将该金额除以小时,得到一个小时费率,乘以该费率,将加班时间分到相应的部门。这些都适用于按科目和部门汇总,但不适用于按部门汇总部分。我已经在下面尽我所能简化了XML和XSL 下面是我的XML:Xml 为每个语句检索上一个变量,xml,xslt,xslt-2.0,Xml,Xslt,Xslt 2.0,我到处都找过了,已经使用XSLT代码好几天了,但我就是搞不懂这个。我会尽力解释,因为这是一个复杂的问题。文件必须按科目和部门汇总,然后有一个抵销行按以下输出中显示的部门汇总 wd:U代码='FLSA-01'的wd:Department不正确。wd:Earning_Code='FLSA-01'交易金额应绑定回wd:Earning_Code='OT'。问题是加班收入代码上可能有多个部门 我必须将FLSA总收入和加班收入总额除以职位,然后除以加班总小时数除以职位。然后,我将该金额除以小时,得到一个小时
<?xml version='1.0' encoding='UTF-8'?>
<wd:Report_Data
xmlns:wd="urn:com.workday.report/bsvc">
<wd:Report_Entry>
<wd:Emplid>831186318</wd:Emplid>
<wd:Ledger_ID>2325</wd:Ledger_ID>
<wd:Earning_Code>OT</wd:Earning_Code>
<wd:Total_PayLine_hours>8.25</wd:Total_PayLine_hours>
<wd:Position>P111827</wd:Position>
<wd:Transaction_Amount>203.61</wd:Transaction_Amount>
<wd:Department>2002000</wd:Department>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Emplid>831186318</wd:Emplid>
<wd:Ledger_ID>6767</wd:Ledger_ID>
<wd:Earning_Code>SALARY</wd:Earning_Code>
<wd:Total_PayLine_hours>8.25</wd:Total_PayLine_hours>
<wd:Position>P111827</wd:Position>
<wd:Transaction_Amount>100</wd:Transaction_Amount>
<wd:Department>2002000</wd:Department>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Emplid>831186318</wd:Emplid>
<wd:Ledger_ID>2325</wd:Ledger_ID>
<wd:Earning_Code>FLSA-01</wd:Earning_Code>
<wd:Total_PayLine_hours>8.25</wd:Total_PayLine_hours>
<wd:Position>P111827</wd:Position>
<wd:Transaction_Amount>132.79</wd:Transaction_Amount>
<wd:Department>2002000</wd:Department>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Emplid>342441735</wd:Emplid>
<wd:Ledger_ID>2387</wd:Ledger_ID>
<wd:Earning_Code>OT</wd:Earning_Code>
<wd:Total_PayLine_hours>2</wd:Total_PayLine_hours>
<wd:Position>P114386</wd:Position>
<wd:Transaction_Amount>86.8</wd:Transaction_Amount>
<wd:Department>2002000</wd:Department>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Emplid>342441735</wd:Emplid>
<wd:Ledger_ID>2387</wd:Ledger_ID>
<wd:Earning_Code>OT</wd:Earning_Code>
<wd:Total_PayLine_hours>8</wd:Total_PayLine_hours>
<wd:Position>P114386</wd:Position>
<wd:Transaction_Amount>347.2</wd:Transaction_Amount>
<wd:Department>2049000</wd:Department>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Emplid>342441735</wd:Emplid>
<wd:Ledger_ID>2387</wd:Ledger_ID>
<wd:Earning_Code>FLSA-01</wd:Earning_Code>
<wd:Total_PayLine_hours>10</wd:Total_PayLine_hours>
<wd:Position>P114386</wd:Position>
<wd:Transaction_Amount>311.44</wd:Transaction_Amount>
<wd:Department>2943000</wd:Department>
</wd:Report_Entry>
<wd:Report_Entry>
<wd:Emplid>342441735</wd:Emplid>
<wd:Ledger_ID>6767</wd:Ledger_ID>
<wd:Earning_Code>SALARY</wd:Earning_Code>
<wd:Total_PayLine_hours>10</wd:Total_PayLine_hours>
<wd:Position>P114386</wd:Position>
<wd:Transaction_Amount>200</wd:Transaction_Amount>
<wd:Department>2049000</wd:Department>
</wd:Report_Entry>
</wd:Report_Data>
是否可以从每个语句的父级复制LedgerAmount变量并按部门匹配??还是有其他方法
非常感谢您的帮助!!!
谢谢,-Remo正如我第一次评论的那样,存储嵌套分组数据的一种方法是使用某种XML结构来存储数据,而不是直接将其作为文本输出,然后您可以轻松地使用中间XML结构中的数据求和,当然也可以输出其他数据:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"
xmlns:wd="urn:com.workday.report/bsvc">
<xsl:output indent="no" method="text"/>
<xsl:template match="/wd:Report_Data">
<header>
<xsl:text>Account</xsl:text><xsl:text>|</xsl:text>
<xsl:text>Department</xsl:text><xsl:text>|</xsl:text>
<xsl:text>Amount</xsl:text>
<xsl:text>
</xsl:text>
</header>
<xsl:for-each-group select="wd:Report_Entry[ wd:Earning_Code != 'FLSA-01']" group-by="wd:Department">
<xsl:variable name="Department" select="current-grouping-key()"/>
<xsl:variable name="groups">
<xsl:for-each-group select="current-group()" group-by="wd:Ledger_ID">
<group>
<ledger-id>
<xsl:value-of select="current-grouping-key()"/>
</ledger-id>
<department>
<xsl:value-of select="$Department"/>
</department>
<!-- The Department on the wd:Earning_Code = 'FLSA-01' is incorrect. I will sum FLSA and OT amount, then divide by the OT hours. Tie back using OT department.-->
<!-- Sum of OT hours by Position -->
<xsl:variable name="SumOfOvertimeHours" select="sum(../wd:Report_Entry[wd:Earning_Code = 'OT' and wd:Position = current-group()/wd:Position]/wd:Total_PayLine_hours)"/>
<!-- To get the Sum Amount of OT and FLSA by position-->
<xsl:variable name="OverTimeandFLSAAmount" select="sum(../wd:Report_Entry[(wd:Ledger_ID = '2325' or wd:Ledger_ID ='2387') and (wd:Position = current-group()/wd:Position) ]/wd:Transaction_Amount )"/>
<!-- To get Hourly Rate for all of Overtime and FLSA-->
<xsl:variable name="OTHourlyRate" select="$OverTimeandFLSAAmount div $SumOfOvertimeHours"/>
<!-- To get the Sum of OT and FLSA to tie Department. Use Hourly rate * hours from OT-->
<xsl:variable name="LedgerAmount" select="format-number($OTHourlyRate * sum(current-group()[wd:Earning_Code = 'OT']/wd:Total_PayLine_hours),'##.00')"/>
<xsl:value-of select="$LedgerAmount"/>
<ledger-amount>
<xsl:value-of select="$LedgerAmount"/>
</ledger-amount>
</group>
</xsl:for-each-group>
</xsl:variable>
<xsl:value-of select="$groups/group/string-join(*, '|')" separator=" "/>
<xsl:text> </xsl:text>
<!-- *****************************************************Offset************************************************************************************** -->
<!-- Ledger ID --><xsl:text>Balance</xsl:text><xsl:text>|</xsl:text>
<!-- Dept ID --><xsl:value-of select="$Department"/><xsl:text>|</xsl:text>
<!-- Sum of OT hours by Position -->
<xsl:variable name="SumOfOTHours" select="sum(../wd:Report_Entry[wd:Earning_Code = 'OT' and wd:Position = current-group()/wd:Position]/wd:Total_PayLine_hours)"/>
<!-- Sum of OT and FLSA amount by Position -->
<xsl:variable name="SumOfOTandFLSAAmount" select="sum(../wd:Report_Entry[( (wd:Ledger_ID = '2387' or wd:Ledger_ID = '2325' ) and wd:Position = current-group()/wd:Position)]/wd:Transaction_Amount)"/>
<!-- To get Hourly Rate for all of Overtime and FLSA-->
<xsl:variable name="OTHourlyRate" select="$SumOfOTandFLSAAmount div $SumOfOTHours"/>
<!-- To get the Sum of OT and FLSA to tie Department. Use Hourly rate * hours from OT-->
<xsl:value-of select="sum($groups/group/ledger-amount)"/>
<xsl:text>
</xsl:text>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
在线示例位于。当初始XML看起来是一个简单的聚合时,XSLT中有相当多的条件使其难以阅读。是的,不幸的是,这是我必须解释的非常奇怪的场景之一。我不指望有人能解决这个问题,但值得一试,哈哈。我把这个问题简化了很多。希望它有意义。试着把它简化得更简单一些。删除所有不需要证明当前问题的内容。谢谢Michael。我还移走了一些东西。如果我脱下其他任何东西,它就不会显示问题。有没有办法从每个语句的父语句中复制LedgerAmount变量并按部门进行匹配?我还不了解所有条件,但如果您想将以前的计算结果存储到计算聚合的总和中,那么可以先将结果存储在XML结构中,而不是直接输出文本。此外,假设您使用诸如Saxon 9或Altova之类的XSLT 2处理器,现在也有支持XSLT 3的更新版本,那么您可以使用xsl:iterate而不是xsl:for each,因为xsl:iterate允许您传递来自前一个迭代步骤的参数。
Account|Department|Amount
2325|2002000|336.40
2387|2002000|149.09
Balance|2002000|607.61
2387|2049000|596.35
Balance|2049000|596.35
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"
xmlns:wd="urn:com.workday.report/bsvc">
<xsl:output indent="no" method="text"/>
<xsl:template match="/wd:Report_Data">
<header>
<xsl:text>Account</xsl:text><xsl:text>|</xsl:text>
<xsl:text>Department</xsl:text><xsl:text>|</xsl:text>
<xsl:text>Amount</xsl:text>
<xsl:text>
</xsl:text>
</header>
<xsl:for-each-group select="wd:Report_Entry[ wd:Earning_Code != 'FLSA-01']" group-by="wd:Department">
<xsl:variable name="Department" select="current-grouping-key()"/>
<xsl:variable name="groups">
<xsl:for-each-group select="current-group()" group-by="wd:Ledger_ID">
<group>
<ledger-id>
<xsl:value-of select="current-grouping-key()"/>
</ledger-id>
<department>
<xsl:value-of select="$Department"/>
</department>
<!-- The Department on the wd:Earning_Code = 'FLSA-01' is incorrect. I will sum FLSA and OT amount, then divide by the OT hours. Tie back using OT department.-->
<!-- Sum of OT hours by Position -->
<xsl:variable name="SumOfOvertimeHours" select="sum(../wd:Report_Entry[wd:Earning_Code = 'OT' and wd:Position = current-group()/wd:Position]/wd:Total_PayLine_hours)"/>
<!-- To get the Sum Amount of OT and FLSA by position-->
<xsl:variable name="OverTimeandFLSAAmount" select="sum(../wd:Report_Entry[(wd:Ledger_ID = '2325' or wd:Ledger_ID ='2387') and (wd:Position = current-group()/wd:Position) ]/wd:Transaction_Amount )"/>
<!-- To get Hourly Rate for all of Overtime and FLSA-->
<xsl:variable name="OTHourlyRate" select="$OverTimeandFLSAAmount div $SumOfOvertimeHours"/>
<!-- To get the Sum of OT and FLSA to tie Department. Use Hourly rate * hours from OT-->
<xsl:variable name="LedgerAmount" select="format-number($OTHourlyRate * sum(current-group()[wd:Earning_Code = 'OT']/wd:Total_PayLine_hours),'##.00')"/>
<xsl:value-of select="$LedgerAmount"/>
<ledger-amount>
<xsl:value-of select="$LedgerAmount"/>
</ledger-amount>
</group>
</xsl:for-each-group>
</xsl:variable>
<xsl:value-of select="$groups/group/string-join(*, '|')" separator=" "/>
<xsl:text> </xsl:text>
<!-- *****************************************************Offset************************************************************************************** -->
<!-- Ledger ID --><xsl:text>Balance</xsl:text><xsl:text>|</xsl:text>
<!-- Dept ID --><xsl:value-of select="$Department"/><xsl:text>|</xsl:text>
<!-- Sum of OT hours by Position -->
<xsl:variable name="SumOfOTHours" select="sum(../wd:Report_Entry[wd:Earning_Code = 'OT' and wd:Position = current-group()/wd:Position]/wd:Total_PayLine_hours)"/>
<!-- Sum of OT and FLSA amount by Position -->
<xsl:variable name="SumOfOTandFLSAAmount" select="sum(../wd:Report_Entry[( (wd:Ledger_ID = '2387' or wd:Ledger_ID = '2325' ) and wd:Position = current-group()/wd:Position)]/wd:Transaction_Amount)"/>
<!-- To get Hourly Rate for all of Overtime and FLSA-->
<xsl:variable name="OTHourlyRate" select="$SumOfOTandFLSAAmount div $SumOfOTHours"/>
<!-- To get the Sum of OT and FLSA to tie Department. Use Hourly rate * hours from OT-->
<xsl:value-of select="sum($groups/group/ledger-amount)"/>
<xsl:text>
</xsl:text>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>