#xml #xslt-2.0
Вопрос:
У меня есть XML, как показано ниже —
lt;?xml version='1.0' encoding='UTF-8'?gt; lt;wd:Report_Data xmlns:wd="urn:com.workday.report/Page_14_Direct_Premiums_Written"gt; lt;wd:Report_Entrygt; lt;wd:Regiongt;ALlt;/wd:Regiongt; lt;wd:Fire_DPWgt;0lt;/wd:Fire_DPWgt; lt;wd:Allied_DPWgt;0lt;/wd:Allied_DPWgt; lt;wd:Private_Flood_DPWgt;0lt;/wd:Private_Flood_DPWgt; lt;wd:Farmowners_Multiple_Peril_DPWgt;0lt;/wd:Farmowners_Multiple_Peril_DPWgt; lt;wd:Homeowners_Multiple_Peril_DPWgt;0lt;/wd:Homeowners_Multiple_Peril_DPWgt; lt;wd:Commercial_Multiple_Peril_Non-Liability_DPWgt;0lt;/wd:Commercial_Multiple_Peril_Non-Liability_DPWgt; lt;wd:CF_SCommercial_Multiple_Peril_Liability_DPWgt;0lt;/wd:CF_SCommercial_Multiple_Peril_Liability_DPWgt; lt;wd:Ocean_Marine_DPWgt;0lt;/wd:Ocean_Marine_DPWgt; lt;wd:Inland_Marine_DPWgt;0lt;/wd:Inland_Marine_DPWgt; lt;wd:Earthquake_DPWgt;0lt;/wd:Earthquake_DPWgt; lt;wd:Workers_Compensation_DPWgt;0lt;/wd:Workers_Compensation_DPWgt; lt;wd:Other_Liability_Occurrence_DPWgt;-431lt;/wd:Other_Liability_Occurrence_DPWgt; lt;wd:Other_Liability_Claims_Made_DPWgt;0lt;/wd:Other_Liability_Claims_Made_DPWgt; lt;wd:Excess_Workers_Compensation_DPWgt;0lt;/wd:Excess_Workers_Compensation_DPWgt; lt;wd:Products_Liability_Occurrence_State_Page_DPWgt;0lt;/wd:Products_Liability_Occurrence_State_Page_DPWgt; lt;wd:Products_Liability_Claims_Made_State_Page_DPWgt;0lt;/wd:Products_Liability_Claims_Made_State_Page_DPWgt; lt;wd:Private_Passenger_Auto_No_Fault_DPWgt;0lt;/wd:Private_Passenger_Auto_No_Fault_DPWgt; lt;wd:Private_Passenger_Auto_Liability_Other_DPWgt;0lt;/wd:Private_Passenger_Auto_Liability_Other_DPWgt; lt;wd:Commercial_Auto_No_Fault_DPWgt;0lt;/wd:Commercial_Auto_No_Fault_DPWgt; lt;wd:Commercial_Auto_Liability_Other_DPWgt;0lt;/wd:Commercial_Auto_Liability_Other_DPWgt; lt;wd:Private_Passenger_Auto_Physical_Damage_DPWgt;0lt;/wd:Private_Passenger_Auto_Physical_Damage_DPWgt; lt;wd:Commercial_Auto_Physical_Damage_DPWgt;0lt;/wd:Commercial_Auto_Physical_Damage_DPWgt; lt;wd:Aircraft_DPWgt;0lt;/wd:Aircraft_DPWgt; lt;wd:Fidelity_DPWgt;0lt;/wd:Fidelity_DPWgt; lt;wd:Surety_DPWgt;0lt;/wd:Surety_DPWgt; lt;wd:Burglary_Theft_DPWgt;0lt;/wd:Burglary_Theft_DPWgt; lt;wd:Boiler_Machinery_DPWgt;0lt;/wd:Boiler_Machinery_DPWgt; lt;/wd:Report_Entrygt; lt;wd:Report_Entrygt; lt;wd:Regiongt;ALlt;/wd:Regiongt; lt;wd:Fire_DPWgt;0lt;/wd:Fire_DPWgt; lt;wd:Allied_DPWgt;0lt;/wd:Allied_DPWgt; lt;wd:Private_Flood_DPWgt;0lt;/wd:Private_Flood_DPWgt; lt;wd:Farmowners_Multiple_Peril_DPWgt;0lt;/wd:Farmowners_Multiple_Peril_DPWgt; lt;wd:Homeowners_Multiple_Peril_DPWgt;0lt;/wd:Homeowners_Multiple_Peril_DPWgt; lt;wd:Commercial_Multiple_Peril_Non-Liability_DPWgt;0lt;/wd:Commercial_Multiple_Peril_Non-Liability_DPWgt; lt;wd:CF_SCommercial_Multiple_Peril_Liability_DPWgt;0lt;/wd:CF_SCommercial_Multiple_Peril_Liability_DPWgt; lt;wd:Ocean_Marine_DPWgt;0lt;/wd:Ocean_Marine_DPWgt; lt;wd:Inland_Marine_DPWgt;0lt;/wd:Inland_Marine_DPWgt; lt;wd:Earthquake_DPWgt;0lt;/wd:Earthquake_DPWgt; lt;wd:Workers_Compensation_DPWgt;2894lt;/wd:Workers_Compensation_DPWgt; lt;wd:Other_Liability_Occurrence_DPWgt;0lt;/wd:Other_Liability_Occurrence_DPWgt; lt;wd:Other_Liability_Claims_Made_DPWgt;0lt;/wd:Other_Liability_Claims_Made_DPWgt; lt;wd:Excess_Workers_Compensation_DPWgt;0lt;/wd:Excess_Workers_Compensation_DPWgt; lt;wd:Products_Liability_Occurrence_State_Page_DPWgt;0lt;/wd:Products_Liability_Occurrence_State_Page_DPWgt; lt;wd:Products_Liability_Claims_Made_State_Page_DPWgt;0lt;/wd:Products_Liability_Claims_Made_State_Page_DPWgt; lt;wd:Private_Passenger_Auto_No_Fault_DPWgt;0lt;/wd:Private_Passenger_Auto_No_Fault_DPWgt; lt;wd:Private_Passenger_Auto_Liability_Other_DPWgt;0lt;/wd:Private_Passenger_Auto_Liability_Other_DPWgt; lt;wd:Commercial_Auto_No_Fault_DPWgt;0lt;/wd:Commercial_Auto_No_Fault_DPWgt; lt;wd:Commercial_Auto_Liability_Other_DPWgt;0lt;/wd:Commercial_Auto_Liability_Other_DPWgt; lt;wd:Private_Passenger_Auto_Physical_Damage_DPWgt;0lt;/wd:Private_Passenger_Auto_Physical_Damage_DPWgt; lt;wd:Commercial_Auto_Physical_Damage_DPWgt;0lt;/wd:Commercial_Auto_Physical_Damage_DPWgt; lt;wd:Aircraft_DPWgt;0lt;/wd:Aircraft_DPWgt; lt;wd:Fidelity_DPWgt;0lt;/wd:Fidelity_DPWgt; lt;wd:Surety_DPWgt;0lt;/wd:Surety_DPWgt; lt;wd:Burglary_Theft_DPWgt;0lt;/wd:Burglary_Theft_DPWgt; lt;wd:Boiler_Machinery_DPWgt;0lt;/wd:Boiler_Machinery_DPWgt; lt;/wd:Report_Entrygt; lt;/wd:Report_Datagt;
Эта структура повторяется несколько раз с несколькими регионами (регионы также могут повторяться) Я должен создать выходной XML, который будет суммировать каждый элемент для одних и тех же регионов, а затем после суммирования каждого элемента. Я должен отобразить сумму всех элементов для региона.
Результат должен быть таким —
lt;Direct_Premiums_Written xmlns:wd="urn:com.workday.report/Page_14_Direct_Premiums_Written" 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"gt; lt;stat:explAKFireDirectPremiumsWrittengt;0lt;/stat:explAKFireDirectPremiumsWrittengt; lt;stat:explAKAlliedLinesDirectPremiumsWrittengt;0lt;/stat:explAKAlliedLinesDirectPremiumsWrittengt; lt;stat:explAKPrivateFloodDirectPremiumsWrittengt;0lt;/stat:explAKPrivateFloodDirectPremiumsWrittengt; lt;stat:explAKFarmownersMultiplePerilDirectPremiumsWrittengt;0lt;/stat:explAKFarmownersMultiplePerilDirectPremiumsWrittengt; lt;stat:explAKHomeownersMultiplePerilDirectPremiumsWrittengt;0lt;/stat:explAKHomeownersMultiplePerilDirectPremiumsWrittengt; lt;stat:explAKCommercialMultiplePerilNonLiabilityPortionDirectPremiumsWrittengt;0lt;/stat:explAKCommercialMultiplePerilNonLiabilityPortionDirectPremiumsWrittengt; lt;stat:explAKCommercialMultiplePerilLiabilityPortionDirectPremiumsWrittengt;0lt;/stat:explAKCommercialMultiplePerilLiabilityPortionDirectPremiumsWrittengt; lt;stat:explAKOceanMarineDirectPremiumsWrittengt;0lt;/stat:explAKOceanMarineDirectPremiumsWrittengt; lt;stat:explAKInlandMarineDirectPremiumsWrittengt;0lt;/stat:explAKInlandMarineDirectPremiumsWrittengt; lt;stat:explAKEarthquakeDirectPremiumsWrittengt;0lt;/stat:explAKEarthquakeDirectPremiumsWrittengt; lt;stat:explAKWorkersCompensationDirectPremiumsWrittengt;-13203lt;/stat:explAKWorkersCompensationDirectPremiumsWrittengt; lt;stat:explAKOtherLiabilityOccurrenceDirectPremiumsWrittengt;-1765lt;/stat:explAKOtherLiabilityOccurrenceDirectPremiumsWrittengt; lt;stat:explAKOtherLiabilityClaimsMadeDirectPremiumsWrittengt;0lt;/stat:explAKOtherLiabilityClaimsMadeDirectPremiumsWrittengt; lt;stat:explAKExcessWorkersCompensationDirectPremiumsWrittengt;0lt;/stat:explAKExcessWorkersCompensationDirectPremiumsWrittengt; lt;stat:explAKProductsLiabilityDirectPremiumsWrittengt;0lt;/stat:explAKProductsLiabilityDirectPremiumsWrittengt; lt;stat:explAKPrivatePassengerAutoNoFaultDirectPremiumsWrittengt;0lt;/stat:explAKPrivatePassengerAutoNoFaultDirectPremiumsWrittengt; lt;stat:explAKOtherPrivatePassengerAutoLiabilityDirectPremiumsWrittengt;0lt;/stat:explAKOtherPrivatePassengerAutoLiabilityDirectPremiumsWrittengt; lt;stat:explAKCommercialAutoNoFaultDirectPremiumsWrittengt;0lt;/stat:explAKCommercialAutoNoFaultDirectPremiumsWrittengt; lt;stat:explAKOtherCommercialAutoLiabilityDirectPremiumsWrittengt;0lt;/stat:explAKOtherCommercialAutoLiabilityDirectPremiumsWrittengt; lt;stat:explAKPrivatePassengerAutoPhysicalDamageDirectPremiumsWrittengt;0lt;/stat:explAKPrivatePassengerAutoPhysicalDamageDirectPremiumsWrittengt; lt;stat:explAKCommercialAutoPhysicalDamageDirectPremiumsWrittengt;0lt;/stat:explAKCommercialAutoPhysicalDamageDirectPremiumsWrittengt; lt;stat:explAKAircraftDirectPremiumsWrittengt;0lt;/stat:explAKAircraftDirectPremiumsWrittengt; lt;stat:explAKFidelityDirectPremiumsWrittengt;0lt;/stat:explAKFidelityDirectPremiumsWrittengt; lt;stat:explAKSuretyDirectPremiumsWrittengt;-1575lt;/stat:explAKSuretyDirectPremiumsWrittengt; lt;stat:explAKBurglaryAndTheftDirectPremiumsWrittengt;0lt;/stat:explAKBurglaryAndTheftDirectPremiumsWrittengt; lt;stat:explAKBoilerAndMachineryDirectPremiumsWrittengt;0lt;/stat:explAKBoilerAndMachineryDirectPremiumsWrittengt; lt;stat:explTotalsADirectPremiumsWrittengt;sum of all above elements for ergion AKlt;/stat:explTotalsADirectPremiumsWrittengt; continue next region....
Till now I have an xslt which is doing sum of individual elements but I am not sure how I can add all derived elements at the end.
Xslt выглядит так —
lt;?xml version="1.0" encoding="UTF-8"?gt; lt;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/Page_14_Direct_Premiums_Written" 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="xs" version="2.0"gt; lt;xsl:output omit-xml-declaration="yes" indent="yes" method="xml"/gt; lt;xsl:template match="node() | @*"gt; lt;xsl:copygt; lt;xsl:apply-templates select="node() | @*"/gt; lt;/xsl:copygt; lt;/xsl:templategt; lt;xsl:template match="wd:Report_Data"gt; lt;Direct_Premiums_Writtengt; lt;xsl:for-each-group select="wd:Report_Entry" group-by="wd:Region"gt; lt;xsl:sort select="wd:Region" order="ascending"/gt; lt;xsl:variable name="tag1"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'FireDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag1}"gt; lt;xsl:value-of select="sum(current-group()/wd:Fire_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag2"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'AlliedLinesDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag2}"gt; lt;xsl:value-of select="sum(current-group()/wd:Allied_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag3"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'PrivateFloodDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag3}"gt; lt;xsl:value-of select="sum(current-group()/wd:Private_Flood_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag4"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'FarmownersMultiplePerilDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag4}"gt; lt;xsl:value-of select="sum(current-group()/wd:Farmowners_Multiple_Peril_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag5"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'HomeownersMultiplePerilDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag5}"gt; lt;xsl:value-of select="sum(current-group()/wd:Homeowners_Multiple_Peril_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag6"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'CommercialMultiplePerilNonLiabilityPortionDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag6}"gt; lt;xsl:value-of select="sum(current-group()/wd:Commercial_Multiple_Peril_Non-Liability_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag7"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'CommercialMultiplePerilLiabilityPortionDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag7}"gt; lt;xsl:value-of select="sum(current-group()/wd:CF_SCommercial_Multiple_Peril_Liability_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag8"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'OceanMarineDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag8}"gt; lt;xsl:value-of select="sum(current-group()/wd:Ocean_Marine_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag9"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'InlandMarineDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag9}"gt; lt;xsl:value-of select="sum(current-group()/wd:Inland_Marine_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag10"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'EarthquakeDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag10}"gt; lt;xsl:value-of select="sum(current-group()/wd:Earthquake_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag11"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'WorkersCompensationDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag11}"gt; lt;xsl:value-of select="sum(current-group()/wd:Workers_Compensation_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag12"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'OtherLiabilityOccurrenceDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag12}"gt; lt;xsl:value-of select="sum(current-group()/wd:Other_Liability_Occurrence_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag13"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'OtherLiabilityClaimsMadeDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag13}"gt; lt;xsl:value-of select="sum(current-group()/wd:Other_Liability_Claims_Made_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag14"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'ExcessWorkersCompensationDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag14}"gt; lt;xsl:value-of select="sum(current-group()/wd:Excess_Workers_Compensation_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag15"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'ProductsLiabilityDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag15}"gt; lt;xsl:value-of select="sum(current-group()/wd:Products_Liability_Occurrence_State_Page_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag16"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'PrivatePassengerAutoNoFaultDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag16}"gt; lt;xsl:value-of select="sum(current-group()/wd:Private_Passenger_Auto_No_Fault_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag17"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'OtherPrivatePassengerAutoLiabilityDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag17}"gt; lt;xsl:value-of select="sum(current-group()/wd:Private_Passenger_Auto_Liability_Other_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag18"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'CommercialAutoNoFaultDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag18}"gt; lt;xsl:value-of select="sum(current-group()/wd:Commercial_Auto_No_Fault_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag19"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'OtherCommercialAutoLiabilityDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag19}"gt; lt;xsl:value-of select="sum(current-group()/wd:Commercial_Auto_Liability_Other_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag20"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'PrivatePassengerAutoPhysicalDamageDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag20}"gt; lt;xsl:value-of select="sum(current-group()/wd:Private_Passenger_Auto_Physical_Damage_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag21"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'CommercialAutoPhysicalDamageDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag21}"gt; lt;xsl:value-of select="sum(current-group()/wd:Commercial_Auto_Physical_Damage_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag22"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'AircraftDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag22}"gt; lt;xsl:value-of select="sum(current-group()/wd:Aircraft_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag23"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'FidelityDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag23}"gt; lt;xsl:value-of select="sum(current-group()/wd:Fidelity_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag24"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'SuretyDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag24}"gt; lt;xsl:value-of select="sum(current-group()/wd:Surety_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag25"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'BurglaryAndTheftDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag25}"gt; lt;xsl:value-of select="sum(current-group()/wd:Burglary_Theft_DPW)"/gt; lt;/xsl:elementgt; lt;xsl:variable name="tag26"gt; lt;xsl:value-of select="concat('stat:expl', current-group()[1]/wd:Region, 'BoilerAndMachineryDirectPremiumsWritten')" /gt; lt;/xsl:variablegt; lt;xsl:element name="{$tag26}"gt; lt;xsl:value-of select="sum(current-group()/wd:Boiler_Machinery_DPW)"/gt; lt;/xsl:elementgt; lt;/xsl:for-each-groupgt; lt;/Direct_Premiums_Writtengt; lt;/xsl:templategt; lt;/xsl:stylesheetgt;
Любая помощь будет признательна.
Ответ №1:
Я бы использовал внутреннюю группировку
lt;xsl:variable name="region" select="current-grouping-key()"/gt; lt;xsl:for-each-group select="current-group()/*[. castable as xs:decimal]" group-by="node-name(.)"gt; lt;xsl:element name="stat:expl{$region}{replace(local-name(), '_', '')}"gt; lt;xsl:value-of select="sum(current-group())"/gt; lt;/xsl:elementgt; lt;/xsl:for-each-groupgt;
plus
lt;stat:explTotalsADirectPremiumsWrittengt; lt;xsl:value-of select="sum(current-group()/*[. castable as xs:decimal])"/gt;gt; lt;/stat:explTotalsADirectPremiumsWrittengt;
для итоговых значений всех элементов.
Комментарии:
1. Спасибо, Мартин. Я использовал логику для суммы, и она сработала, но она дает мне такое значение lt;stat:expltotalsadirectpremiumswritengt;-2.7605954799999995E6gt; lt;stat:expltotalsadirectpremiumswritengt;lt;/stat:expltotalsadirectpremiumswritengt;. Мож ем ли мы показать это как целое число без десятичных знаков или до 2 знаков после запятой?
2. Кроме того, для первой логики, для функции замены, она выдает ошибку,потому что она принимает первый параметр с пространством имен отчета, например «urn:com.workday.report/страница 14_direct_premiums_written», Fire_DPW. Как это можно исправить?
3. @VJain, используйте, например
sum(current-group()/xs:decimal(.))
, для большей точности, и, конечно, вы можете использоватьformat-number
по мере необходимости, напримерformat-number(sum(current-group()/xs:decimal(.)), '0.00')
.4. @VJain, что касается замены, извините за это, вы не указали никаких правил для имен элементов результата, но вы правы, что попытка,
node-name()
вероятно, не соответствует вашим примерам, проверьте, работает ли редактирование сlocal-name()
replace
аргументом лучше.