【发布时间】:2022-01-12 20:56:22
【问题描述】:
我有一个如下的 XML -
<Page14 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:statutorytype="us-stat-2020-annual-stmt-pc"
xmlns:xbrli="http://www.xbrl.org/2001/instance"
xmlns:iso4217="http://www.xe.com/iso4217.htm"
xmlns:stat="urn:www-iasa-org/tempuri">
<RegionRow>
<Region>HI</Region>
<EachUniqueCombo>
<CurrentGroup>20000|16 Workers' Compensation|IBNR Loss Reserves|Pooled</CurrentGroup>
<LedgerAccount>20000</LedgerAccount>
<LOB>16 Workers' Compensation</LOB>
<SpendCategory>IBNR Loss Reserves</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-31</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>20100|16 Workers' Compensation|IBNR ALAE D&CC Reserves|Pooled</CurrentGroup>
<LedgerAccount>20100</LedgerAccount>
<LOB>16 Workers' Compensation</LOB>
<SpendCategory>IBNR ALAE D&CC Reserves</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-1</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>24000|16 Workers' Compensation||Pooled</CurrentGroup>
<LedgerAccount>24000</LedgerAccount>
<LOB>16 Workers' Compensation</LOB>
<SpendCategory/>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-45.13</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>40000|16 Workers' Compensation||Pooled</CurrentGroup>
<LedgerAccount>40000</LedgerAccount>
<LOB>16 Workers' Compensation</LOB>
<SpendCategory/>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-65</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>40010|16 Workers' Compensation||Pooled</CurrentGroup>
<LedgerAccount>40010</LedgerAccount>
<LOB>16 Workers' Compensation</LOB>
<SpendCategory/>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-5.34</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>50000|16 Workers' Compensation|Change in IBNR Loss Reserves|Pooled</CurrentGroup>
<LedgerAccount>50000</LedgerAccount>
<LOB>16 Workers' Compensation</LOB>
<SpendCategory>Change in IBNR Loss Reserves</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-16</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>50100|16 Workers' Compensation|Change in IBNR ALAE D&CC Reserves|Pooled</CurrentGroup>
<LedgerAccount>50100</LedgerAccount>
<LOB>16 Workers' Compensation</LOB>
<SpendCategory>Change in IBNR ALAE D&CC Reserves</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>1</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>51000|16 Workers' Compensation|Change in Commission Reserves|Pooled</CurrentGroup>
<LedgerAccount>51000</LedgerAccount>
<LOB>16 Workers' Compensation</LOB>
<SpendCategory>Change in Commission Reserves</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-1</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>51000|16 Workers' Compensation|Paid Commissions|Pooled</CurrentGroup>
<LedgerAccount>51000</LedgerAccount>
<LOB>16 Workers' Compensation</LOB>
<SpendCategory>Paid Commissions</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-0.05</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>20000|17.1 Other Liability - Bodily Injury, Occurrence|IBNR Loss Reserves|Pooled</CurrentGroup>
<LedgerAccount>20000</LedgerAccount>
<LOB>17.1 Other Liability - Bodily Injury, Occurrence</LOB>
<SpendCategory>IBNR Loss Reserves</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-28</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>20100|17.1 Other Liability - Bodily Injury, Occurrence|IBNR ALAE D&CC Reserves|Pooled</CurrentGroup>
<LedgerAccount>20100</LedgerAccount>
<LOB>17.1 Other Liability - Bodily Injury, Occurrence</LOB>
<SpendCategory>IBNR ALAE D&CC Reserves</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>135</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>24000|17.1 Other Liability - Bodily Injury, Occurrence||Pooled</CurrentGroup>
<LedgerAccount>24000</LedgerAccount>
<LOB>17.1 Other Liability - Bodily Injury, Occurrence</LOB>
<SpendCategory/>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>19.17</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>40000|17.1 Other Liability - Bodily Injury, Occurrence||Pooled</CurrentGroup>
<LedgerAccount>40000</LedgerAccount>
<LOB>17.1 Other Liability - Bodily Injury, Occurrence</LOB>
<SpendCategory/>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>22</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>40010|17.1 Other Liability - Bodily Injury, Occurrence||Pooled</CurrentGroup>
<LedgerAccount>40010</LedgerAccount>
<LOB>17.1 Other Liability - Bodily Injury, Occurrence</LOB>
<SpendCategory/>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-21.24</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>50000|17.1 Other Liability - Bodily Injury, Occurrence|Change in IBNR Loss Reserves|Pooled</CurrentGroup>
<LedgerAccount>50000</LedgerAccount>
<LOB>17.1 Other Liability - Bodily Injury, Occurrence</LOB>
<SpendCategory>Change in IBNR Loss Reserves</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-261</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>50100|17.1 Other Liability - Bodily Injury, Occurrence|Change in IBNR ALAE D&CC Reserves|Pooled</CurrentGroup>
<LedgerAccount>50100</LedgerAccount>
<LOB>17.1 Other Liability - Bodily Injury, Occurrence</LOB>
<SpendCategory>Change in IBNR ALAE D&CC Reserves</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-135</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>51000|17.1 Other Liability - Bodily Injury, Occurrence|Change in Commission Reserves|Pooled</CurrentGroup>
<LedgerAccount>51000</LedgerAccount>
<LOB>17.1 Other Liability - Bodily Injury, Occurrence</LOB>
<SpendCategory>Change in Commission Reserves</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>1</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>51000|17.1 Other Liability - Bodily Injury, Occurrence|Paid Commissions|Pooled</CurrentGroup>
<LedgerAccount>51000</LedgerAccount>
<LOB>17.1 Other Liability - Bodily Injury, Occurrence</LOB>
<SpendCategory>Paid Commissions</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-3.3</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>20000|17.1 Other Liability - Physical Damage, Occurrence|IBNR Loss Reserves|Pooled</CurrentGroup>
<LedgerAccount>20000</LedgerAccount>
<LOB>17.1 Other Liability - Physical Damage, Occurrence</LOB>
<SpendCategory>IBNR Loss Reserves</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>1</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>50000|17.1 Other Liability - Physical Damage, Occurrence|Change in IBNR Loss Reserves|Pooled</CurrentGroup>
<LedgerAccount>50000</LedgerAccount>
<LOB>17.1 Other Liability - Physical Damage, Occurrence</LOB>
<SpendCategory>Change in IBNR Loss Reserves</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-1</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>20000|24 Surety|IBNR Loss Reserves|Pooled</CurrentGroup>
<LedgerAccount>20000</LedgerAccount>
<LOB>24 Surety</LOB>
<SpendCategory>IBNR Loss Reserves</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-458</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>20100|24 Surety|IBNR ALAE D&CC Reserves|Pooled</CurrentGroup>
<LedgerAccount>20100</LedgerAccount>
<LOB>24 Surety</LOB>
<SpendCategory>IBNR ALAE D&CC Reserves</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-24</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>24000|24 Surety||Pooled</CurrentGroup>
<LedgerAccount>24000</LedgerAccount>
<LOB>24 Surety</LOB>
<SpendCategory/>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>354.28</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>40010|24 Surety||Pooled</CurrentGroup>
<LedgerAccount>40010</LedgerAccount>
<LOB>24 Surety</LOB>
<SpendCategory/>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-819</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>50000|24 Surety|Change in IBNR Loss Reserves|Pooled</CurrentGroup>
<LedgerAccount>50000</LedgerAccount>
<LOB>24 Surety</LOB>
<SpendCategory>Change in IBNR Loss Reserves</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>-292</Sum>
</EachUniqueCombo>
<EachUniqueCombo>
<CurrentGroup>50100|24 Surety|Change in IBNR ALAE D&CC Reserves|Pooled</CurrentGroup>
<LedgerAccount>50100</LedgerAccount>
<LOB>24 Surety</LOB>
<SpendCategory>Change in IBNR ALAE D&CC Reserves</SpendCategory>
<PooledWorktag>Pooled</PooledWorktag>
<Sum>24</Sum>
</EachUniqueCombo>
</RegionRow>
<RegionRow>
<Region>AL</Region>
----
</RegionRow>
</Page14>
对于上述 XML,我需要编写一个针对每个 RegionRow 元素和每个区域内运行的 xslt,我需要首先基于 LOB 元素进行分组,然后在此基础上我需要对元素“Sum”进行求和在某些分类账上。
我正在尝试如下编写 xslt -
<?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" xmlns:wd="urn:com.workday.report/CR_Page_14_EMC"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:statutorytype="us-stat-2020-annual-stmt-pc"
xmlns:xbrli="http://www.xbrl.org/2001/instance" xmlns:iso4217="http://www.xe.com/iso4217.htm"
xmlns:stat="urn:www-iasa-org/tempuri" exclude-result-prefixes=" wd xs" version="2.0">
<xsl:output indent="yes" method="xml"/>
<xsl:variable name="single_quote">
<xsl:text>'</xsl:text>
</xsl:variable>
<xsl:variable name="ampersand">
<xsl:text>&</xsl:text>
</xsl:variable>
<xsl:template match="Page14">
<OutputOfNextXSL>
<xsl:for-each select="RegionRow">
<RowData>
<Region>
<xsl:value-of select="Region"/>
</Region>
<xsl:for-each-group select="EachUniqueCombo" group-by="EachUniqueCombo[LOB = '24 Surety']">
<CellOneAllied>
<!-- ledger account xyz, -->
<xsl:value-of
select="-1 * sum(EachUniqueCombo[LedgerAccount = '40000' or LedgerAccount = '20000']/xs:decimal(Sum))"/>
</CellOneAllied>
<CellTwoAllied>
</CellTwoAllied>
---
--
</xsl:for-each-group>
<xsl:for-each-group select= EachUniqueCombo group-by=EachUniqueCombo[LOB = '16 Workers' Compensation']">
<!-- Sum here based on one or multiple ledger accounts-->
</xsl:for-each-group>
分组依据可以基于 1 个 LOB 或多个,类似地,我需要进行总和的分组内的分类帐帐户/支出类别也可以是单个或多个。我无法根据上述分组逻辑获得任何值,然后也无法到达组内的分类帐帐户或支出类别以进行总和。 有人可以帮助实现这一目标吗?
【问题讨论】:
-
在询问 XSLT 问题时,您需要提供 minimal reproducible example: (1) 输入 XML。 (2) 你的逻辑,以及试图实现它的 XSLT。 (3) 所需的输出,基于上面#1 中的示例 XML。 (4) XSLT 处理器及其对 XSLT 标准的遵从性:1.0、2.0 或 3.0。
-
我不清楚你想要实现什么,无论是从你的口头描述还是像
xsl:for-each-group select="EachUniqueCombo" group-by="EachUniqueCombo[LOB = '24 Surety']"这样的代码,因为它选择上下文节点的所有EachUniqueCombo子元素作为分组人口和尝试通过由人口中每个项目的EachUniqueCombo[LOB = '24 Surety']子元素形成的键对它们进行分组。由于您的EachUniqueCombo元素似乎没有嵌套,因此没有任何意义。也许您只是想选择和求和,例如sum(EachUniqueCombo[LOB = '24 Surety']/Sum).