0

We need a solution to add the count for each node by using XSLT.The count value should take it from the BIG node Records and add to the next node "NTE" and etc.

for example in below xml element BIG exist only one time and NTE ,BSE repeated.

I have input xml below,

<?xml version = '1.0' encoding = 'UTF-8'?>
<PORoot>
    <BIG>
        <ER-CUST-ACCOUNT>123</ER-CUST-ACCOUNT>
        <ER-SEG-SEQ/>
    </BIG>
    <NTE>
        <ER-CUST-ACCOUNT>123</ER-CUST-ACCOUNT>
        <ER-EXP-SEG-SEQ/>
    </NTE>
    <NTE>
        <ER-CUST-ACCOUNT>123</ER-CUST-ACCOUNT>
        <ER-EXP-SEG-SEQ/>
    </NTE>
    <NTE>
        <ER-CUST-ACCOUNT>123</ER-CUST-ACCOUNT>
        <ER-EXP-SEG-SEQ/>
    </NTE>
    <BSE>
        <ER-CUST-ACCOUNT>123</ER-CUST-ACCOUNT>
        <ER-EXP-SEG-SEQ/>
    </BSE>
    <BSE>
        <ER-CUST-ACCOUNT>123</ER-CUST-ACCOUNT>
        <ER-EXP-SEG-SEQ/>
    </BSE>
</PORoot>


<?xml version = '1.0' encoding = 'UTF-8'?>
<PORoot>
    <BIG>
        <ER-CUST-ACCOUNT>123</ER-CUST-ACCOUNT>
        <ER-SEG-SEQ>1</ER-SEG-SEQ>
    </BIG>
    <NTE>
        <ER-CUST-ACCOUNT>123</ER-CUST-ACCOUNT>
        <ER-EXP-SEG-SEQ>2</ER-EXP-SEG-SEQ>
    </NTE>
    <NTE>
        <ER-CUST-ACCOUNT>123</ER-CUST-ACCOUNT>
        <ER-EXP-SEG-SEQ>3</ER-EXP-SEG-SEQ>
    </NTE>
    <NTE>
        <ER-CUST-ACCOUNT>123</ER-CUST-ACCOUNT>
        <ER-EXP-SEG-SEQ>4</ER-EXP-SEG-SEQ>
    </NTE>
    <BSE>
        <ER-CUST-ACCOUNT>123</ER-CUST-ACCOUNT>
        <ER-EXP-SEG-SEQ>5</ER-EXP-SEG-SEQ>
    </BSE>
    <BSE>
        <ER-CUST-ACCOUNT>123</ER-CUST-ACCOUNT>
        <ER-EXP-SEG-SEQ>6</ER-EXP-SEG-SEQ>
    </BSE>
</PORoot>
Raju
  • 1
  • 2
  • Does this answer your question? [Counter inside xsl:for-each loop](https://stackoverflow.com/questions/93511/counter-inside-xslfor-each-loop) – Natrium Aug 09 '23 at 12:49
  • Your question is not clear. Can there be more than one BIG element, and if so, should the count restart at each? – michael.hor257k Aug 09 '23 at 12:52
  • 1
    P.S. Please edit your question and add your attempted XSLT code. – michael.hor257k Aug 09 '23 at 12:53
  • There will be only one BIG element, and the count should take it from top to bottom for all records. I have tried with positions but no luck – Raju Aug 09 '23 at 13:28
  • 1
    Again, post your attempt so we can fix it, instead of having to write your code for you from scratch. – michael.hor257k Aug 09 '23 at 13:33
  • Sure, i will provide the code snippet soon, There are total 800 elements in input xml and i have added here only the problematic statement. i will adjust the code and i will post here. Thank you Michael for your quick response – Raju Aug 09 '23 at 13:43
  • 1
    Please post only the minimum required to demonstrate the problem - see: [mcve]. – michael.hor257k Aug 09 '23 at 14:08

1 Answers1

2

Here is one possible approach:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="ER-SEG-SEQ|ER-EXP-SEG-SEQ">
    <xsl:copy>
        <xsl:number count="PORoot/*"/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>
y.arazim
  • 866
  • 2
  • 10