Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7597011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:03:52+00:00 2026-05-30T22:03:52+00:00

Can someone please help me out with this scenario asap? Input XML: <dataXML> <Items>

  • 0

Can someone please help me out with this scenario asap?

Input XML:

<dataXML>
<Items>
    <itemLine>
        <lineNo>1</lineNo>
        <lineRefNo>001</lineRefNo>
        <lineDes>test1</lineDes>
    </itemLine>
    <itemLine>
        <lineNo>2</lineNo>
        <lineRefNo>001</lineRefNo>
        <lineDes>test2</lineDes>
    </itemLine>
    <itemLine>
        <lineNo>3</lineNo>
        <lineRefNo>002</lineRefNo>
        <lineDes>test3</lineDes>
    </itemLine>
    <itemLine>
        <lineNo>4</lineNo>
        <lineRefNo>002</lineRefNo>
        <lineDes>test4</lineDes>
    </itemLine>
    <itemLine>
        <lineNo>5</lineNo>
        <lineRefNo>002</lineRefNo>
        <lineDes>test5</lineDes>
    </itemLine>
    <itemLine>
        <lineNo>6</lineNo>
        <lineRefNo>003</lineRefNo>
        <lineDes>test6</lineDes>
    </itemLine>
</Items>

I have regrouped item lines based on LineRefNo

Transformation xsl:

    <?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
    <xsl:variable name="totalLine" select="count(dataXML/Items/itemLine)" />

<Root>
    <xsl:value-of select="concat('&lt;','test','&gt;')" disable-output-escaping="yes"/>
    <xsl:for-each select="dataXML/Items/itemLine">
        <xsl:choose>
        <xsl:when test="lineRefNo != preceding-sibling::itemLine[1]/lineRefNo">
            <xsl:value-of select="concat('&lt;/','test','&gt;')" disable-output-escaping="yes"/>
            <xsl:value-of select="concat('&lt;','test','&gt;')" disable-output-escaping="yes"/>
            <item>
                <xsl:value-of select="concat('Line No : ',position())" />,<xsl:value-of select="lineRefNo" />
            </item>
            <xsl:if test="$totalLine = position()">
                <xsl:value-of select="concat('&lt;/','test','&gt;')" disable-output-escaping="yes"/>
            </xsl:if>
        </xsl:when>
        <xsl:otherwise>
            <item>
                <xsl:value-of select="concat('Line No : ',position())" />,<xsl:value-of select="lineRefNo" />
            </item>
            <xsl:if test="$totalLine = position()">
                <xsl:value-of select="concat('&lt;/','test','&gt;')" disable-output-escaping="yes"/>
            </xsl:if>
        </xsl:otherwise>
        </xsl:choose>
    </xsl:for-each>
</Root>
</xsl:template>
</xsl:stylesheet>

Note : Please escape ‘>’ and ‘<‘ in xslt transformation where Test and Item tags are used

It will transform input xml as below result

 **Result :**
 <?xml version="1.0" encoding="UTF-8"?>
<Root>
    <test>
        <item>Line No : 1,001</item>
        <item>Line No : 2,001</item>
    </test>
    <test>
        <item>Line No : 3,002</item>
        <item>Line No : 4,002</item>
        <item>Line No : 5,002</item>
    </test>
    <test>
        <item>Line No : 6,003</item>
    </test>
</Root>

**Expected Result:**
<?xml version="1.0" encoding="UTF-8"?>
<Root>
    <test>
        <item>Line No : 1,001</item>
        <item>Line No : 2,001</item>
    </test>
    <test>
        <item>Line No : 1,002</item>
        <item>Line No : 2,002</item>
        <item>Line No : 3,002</item>
    </test>
    <test>
        <item>Line No : 1,003</item>
    </test>
</Root>

Thanking in Advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:03:53+00:00Added an answer on May 30, 2026 at 10:03 pm

    This transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:key name="kItemsByRef" match="itemLine"
      use="lineRefNo"/>
    
     <xsl:template match=
      "itemLine
         [generate-id()
         =
          generate-id(key('kItemsByRef', lineRefNo)[1])
         ]
      ">
      <test>
       <xsl:for-each select="key('kItemsByRef', lineRefNo)">
         <item>Line No : <xsl:value-of select=
          "concat(position(), ',', lineRefNo)"/>
          </item>
       </xsl:for-each>
      </test>
     </xsl:template>
     <xsl:template match="text()"/>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <dataXML>
        <Items>
            <itemLine>
                <lineNo>1</lineNo>
                <lineRefNo>001</lineRefNo>
                <lineDes>test1</lineDes>
            </itemLine>
            <itemLine>
                <lineNo>2</lineNo>
                <lineRefNo>001</lineRefNo>
                <lineDes>test2</lineDes>
            </itemLine>
            <itemLine>
                <lineNo>3</lineNo>
                <lineRefNo>002</lineRefNo>
                <lineDes>test3</lineDes>
            </itemLine>
            <itemLine>
                <lineNo>4</lineNo>
                <lineRefNo>002</lineRefNo>
                <lineDes>test4</lineDes>
            </itemLine>
            <itemLine>
                <lineNo>5</lineNo>
                <lineRefNo>002</lineRefNo>
                <lineDes>test5</lineDes>
            </itemLine>
            <itemLine>
                <lineNo>6</lineNo>
                <lineRefNo>003</lineRefNo>
                <lineDes>test6</lineDes>
            </itemLine>
        </Items>
    </dataXML>
    

    produces the wanted, correct result:

    <test>
       <item>Line No : 1,001</item>
       <item>Line No : 2,001</item>
    </test>
    <test>
       <item>Line No : 1,002</item>
       <item>Line No : 2,002</item>
       <item>Line No : 3,002</item>
    </test>
    <test>
       <item>Line No : 1,003</item>
    </test>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please help me out with a JavaScript/jQuery solution for this arithmetic problem:
Can someone please help me out with this? I'm using jquery-1.4.2. http://jsfiddle.net/Ymkpb/ Thank you
can someone please help me out writing this code in objective C : function
Can someone please help me out with printing the contents of an IFrame via
Can someone please help me figure out a way to achieve the following (see
can someone please help me. why does this return an error: Dim stuff As
Could someone please help explain why I can't get this to work? I properly
Can someone please help me out? My code for splitting the strings is working
Can someone please help me out... I've tried all kinds of things (including help
Can someone please help me out with a query? In Microsoft SQL Server, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.