0

XSLT

<xsl:stylesheet xmlns:xalan="http://xml.apache.org/xalan" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0">
        <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
        <xsl:template match="Data">
            <xsl:element name="Data">
                <xsl:call-template name="SubjectData" />
            </xsl:element>
        </xsl:template>
        <xsl:template name="SubjectData">
            <xsl:element name="SubjectData">
                <xsl:for-each select="/Data/SubjectData/SubjectIND[@AECBInquiryFlag='0' and @AECBConsentFlag='0']">
                    <xsl:variable name="index" select="position()" />
                    <xsl:element name="SubjectIND">
                        <xsl:copy-of select="@*" />
                        <xsl:element name="ExternalSources">
                            <xsl:copy-of select="ExternalSources/@*" />
                            <xsl:element name="UAEbureau">
                                <xsl:attribute name="ResponseId">
                                    <xsl:value-of select="/Data/CIPConnectorOutput/AdapterOutput/AdapterResult/Response[$index]/Report/ResponseId" />
                                </xsl:attribute>
                                <xsl:element name="Contracts">
                                    <xsl:for-each select="/Data/CIPConnectorOutput/AdapterOutput/AdapterResult/Response[$index]/Report/Response/ContractData/Installments/Contract">
                                        <xsl:element name="Contract">
                                            <xsl:attribute name="TotalAmount">
                                                <xsl:value-of select="TotalAmount" />
                                            </xsl:attribute>
                                  <xsl:for-each select="History">
                                      <xsl:sort select="@Year" order="descending"/>
                                      <xsl:variable name="key" select="@Year"/>
                                      <xsl:if test="not(preceding-sibling::History[@Year=$key])">
                                          <xsl:element name="History">
                                              <xsl:attribute name="Year"><xsl:value-of select="@Year"/></xsl:attribute>
                                              <xsl:element name="Period">
                                              </xsl:element>
                                          </xsl:element>
                                      </xsl:if>
                                  </xsl:for-each>
                                        </xsl:element>
                                    </xsl:for-each>
                                </xsl:element>
                            </xsl:element>
                        </xsl:element>
                    </xsl:element>
                </xsl:for-each>
            </xsl:element>
        </xsl:template>
    </xsl:stylesheet>

Input Xml

    <Data>
        <CIPConnectorOutput>
            <AdapterOutput>
                <ResultMessage Code="SUCCESS"/>
                <AdapterResult>
                    <Response DetailID="25480276" ID="1">
                        <Report>
                            <ResponseId>735f28fd-2d04-43c8-bf91-58f295fe132a</ResponseId>
                            <Response>
                                <ContractData>
                                    <Installments>
                                        <Contract>
                                            <TotalAmount>18888</TotalAmount>

                                            <History Year="2018">
                                                <ReferenceDate>032018</ReferenceDate>
                                                <Balance>175000</Balance>
                                                <OverdueAmount>200</OverdueAmount>
                                                <DaysPaymentDelay>2</DaysPaymentDelay>
                                                <ContractStatus>U</ContractStatus>
                                            </History>
                                            <History Year="2018">
                                                <ReferenceDate>032018</ReferenceDate>
                                                <Balance>885000</Balance>
                                                <OverdueAmount>100</OverdueAmount>
                                                <DaysPaymentDelay>1</DaysPaymentDelay>
                                                <ContractStatus>U</ContractStatus>
                                            </History>
                                            <History Year="2018">
                                                <ReferenceDate>012018</ReferenceDate>
                                                <Balance>335000</Balance>
                                                <OverdueAmount>0</OverdueAmount>
                                                <DaysPaymentDelay>0</DaysPaymentDelay>
                                                <ContractStatus>U</ContractStatus>
                                            </History>
                                            <History Year="2017">
                                                <ReferenceDate>122017</ReferenceDate>
                                                <Balance>55554</Balance>
                                            </History>
                                        </Contract>
                                        <Contract>
                                            <TotalAmount>180000</TotalAmount>
                                            <History Year="2018">
                                                <ReferenceDate>032018</ReferenceDate>
                                                <Balance>275000</Balance>
                                                <OverdueAmount>200</OverdueAmount>
                                                <DaysPaymentDelay>2</DaysPaymentDelay>
                                                <ContractStatus>U</ContractStatus>
                                            </History>
                                            <History Year="2017">
                                                <ReferenceDate>022018</ReferenceDate>
                                                <Balance>675000</Balance>
                                                <OverdueAmount>100</OverdueAmount>
                                                <DaysPaymentDelay>1</DaysPaymentDelay>
                                                <ContractStatus>U</ContractStatus>
                                            </History>
                                            <History Year="2015">
                                                <ReferenceDate>012015</ReferenceDate>
                                                <Balance>185000</Balance>
                                                <OverdueAmount>0</OverdueAmount>
                                                <DaysPaymentDelay>0</DaysPaymentDelay>
                                                <ContractStatus>U</ContractStatus>
                                            </History>
                                        </Contract>
                                    </Installments>
                                </ContractData>
                            </Response>
                        </Report>
                    </Response>
                </AdapterResult>
            </AdapterOutput>
        </CIPConnectorOutput>
        <SubjectData>
            <SubjectIND AECBConsentFlag="0" AECBInquiryFlag="0" Age="56" CHMCallDone="" DOB="1963-04-08" EmiratesID="784-1963-5878784-1" FullName="ROSS GIULI" Gender="F" Name="ROSS" NameAR="sdfg" Nationality="UAE" Role="M" Surname="GIULI" SurnameAR="sdfg">
                <ExternalSources />
            </SubjectIND>
        </SubjectData>
    </Data>

Output XML

    <?xml version="1.0" encoding="UTF-8"?>
    <Data>
        <SubjectData>
            <SubjectIND AECBConsentFlag="0" AECBInquiryFlag="0" Age="56" CHMCallDone="" DOB="1963-04-08"
                EmiratesID="784-1963-5878784-1" FullName="ROSS GIULI" Gender="F" Name="ROSS"
                NameAR="sdfg" Nationality="UAE" Role="M" Surname="GIULI" SurnameAR="sdfg">
                <ExternalSources>
                    <UAEbureau ResponseId="735f28fd-2d04-43c8-bf91-58f295fe132a">
                        <Contracts>
                            <Contract TotalAmount="18888">
                                <History Year="2018">
                                        <Period RefDate="032018"  Balance="175000" />
                                        <Period RefDate="022018" Balance="885000" />
                                        <Period RefDate="012018" Balance="335000" />
                                </History>
                                <History Year="2017">
                                        <Period RefDate="122017"  Balance="55554" />
                                </History>
                             </Contract>
                            <Contract TotalAmount="180000">
                                 <History Year="2016">
                                        <Period RefDate="032018"  Balance="275000" />
                                        <Period RefDate="022018" Balance="675000" />

                                </History>
                                <History Year="2015">
                                        <Period RefDate="012015" Balance="185000" />
                                </History>
                            </Contract>
                        </Contracts>
                    </UAEbureau>
                </ExternalSources>
            </SubjectIND>
        </SubjectData>
    </Data>

i want to group by year in xslt please find below input sample xsl and output expected. please help any solution. i have tried with below xsl but is not working let me know if anyone have alternative solution for this. i require it using xslt 1.0 not by 2.0 Number of history to be split as per year and output will shown as below.

Tim C
  • 70,053
  • 14
  • 74
  • 93
  • I suggest you try again, after reading this: http://www.jenitennison.com/xslt/grouping/muenchian.html – michael.hor257k Aug 28 '19 at 12:39
  • Voting to close because this seems to be a completely bog-standard XSLT 1.0 grouping question with no significant differences from all the other grouping questions on this site. I selected one of those as the "duplicate" but you probably want to look at others - or better still, at a standard reference on XSLT. Note that grouping is MUCH easier in XSLT 2.0, and using a 1.0 processor (Xalan) 20 years after 1.0 was created seems rather luddite these days. – Michael Kay Aug 28 '19 at 14:31
  • @MichaelKay its not duplicate if you have solution please provide it but remember please dont mark it as duplicate. grouping in xslt may similar but here i want output in different way which explained in description – Nikhil Karande Sep 06 '19 at 06:17

0 Answers0