我是xslt的新手。我尝试按2个不同的元素分组。首先是工人,然后是工资代码。请通过付费代码查看该金额的总和。下面是一个前样本xsl,然后是xsl之后的样本,我想作为输出。
在:
<?xml version='1.0' encoding='utf-8'?>
<File xmlns:is="java:com.workday.esb.intsys.xpath.ParsedIntegrationSystemFunctions"
xmlns:tv="java:com.workday.esb.intsys.TypedValue">
<Worker>
<Detail>
<EmployeeID>0008765</EmployeeID>
<FirstName>ROBERT</FirstName>
<PayCode>RSVEST</PayCode>
<Amount>5572.800000</Amount>
</Detail>
<Detail>
<EmployeeID>0008765</EmployeeID>
<FirstName>ROBERT</FirstName>
<PayCode>FICA</PayCode>
<Amount>40.000000</Amount>
</Detail>
</Worker>
<Worker>
<Detail>
<EmployeeID>0008765</EmployeeID>
<FirstName>ROBERT</FirstName>
<PayCode>RSVEST</PayCode>
<Amount>13545.000000</Amount>
</Detail>
</Worker>
<Worker>
<Detail>
<EmployeeID>00012345</EmployeeID>
<FirstName>RUSSELL</FirstName>
<PayCode>RSVEST</PayCode>
<Amount>84811.050000</Amount>
</Detail>
</Worker>
</File>
我想要的输出是什么,先由工人分组,然后按工资代码分组。由于分组,金额总和:
<?xml version='1.0' encoding='utf-8'?>
<File xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tv="java:com.workday.esb.intsys.TypedValue">
<Worker>
<Detail>
<EmployeeID>0008765</EmployeeID>
<FirstName>ROBERT</FirstName>
<PayCode>RSVEST</PayCode>
<Amount>19117.800000</Amount>
</Detail>
<Detail>
<EmployeeID>0008765</EmployeeID>
<FirstName>ROBERT</FirstName>
<PayCode>FICA</PayCode>
<Amount>40.000000</Amount>
</Detail>
</Worker>
<Worker>
<Detail>
<EmployeeID>00012345</EmployeeID>
<FirstName>RUSSELL</FirstName>
<PayCode>RSVEST</PayCode>
<Amount>84811.050000</Amount>
</Detail>
</Worker>
</File>
以下是我的XSL无效:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" exclude-result-prefixes="xsl wd xsd this env"
xmlns:wd="urn:com.workday/bsvc"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:this="urn:this-stylesheet">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="/">
<File>
<Worker>
<xsl:for-each-group select="File" group-by="Worker">
<Detail>
<EmployeeID><xsl:value-of select="Worker/current-group()/EmployeeID"></xsl:value-of></EmployeeID>
<FirstName><xsl:value-of select="//current-group()//FirstName"></xsl:value-of></FirstName>
<PayCode><xsl:value-of select="PayCode"></xsl:value-of></PayCode>
<Amount><xsl:value-of select="format-number(sum(current-group()/number(translate(Amount,',',''))),'######.00')"></xsl:value-of></Amount>
</Detail>
</xsl:for-each-group>
</Worker>
</File>
</xsl:template>
</xsl:stylesheet>
有人可以把SL转换成所需的输出吗? 我已经工作了几个小时,挥舞着白旗哈哈。
谢谢!
答案 0 :(得分:1)
如果您想为每个EmployeeID
创建一个组,并且在每个此类组中为每个PayCode
创建一个子组,那么显然您需要嵌套两个 {{1说明。您需要分组的节点是xsl:for-each-group
元素,而不是只有一个元素的根Detail
元素。
XSLT 2.0
File