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

  • SEARCH
  • Home
  • 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 8671031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:50:54+00:00 2026-06-12T18:50:54+00:00

I need some help in transforming an input data which is from reading a

  • 0

I need some help in transforming an input data which is from reading a csv file. I would like to convert it into a structure that is a little more intelligent. I was thinking there is probably some cumulative processing, but not sure how to go about it.

My input XML:

<lines>
    <line number="1">Header, some header data 1</line>
    <line number="2">Data, some data for 1</line>
    <line number="3">Data, some data for 1</line>
    <line number="4">Header, some header data for 2</line>
    <line number="5">Data some data for 2</line>
</lines>

Required output is to classify into chunks using the word Header.

<?xml version="1.0" encoding="UTF-8"?>
<lines>
    <Block>
        <line number="1">Header, some header data 1</line>
        <line number="2">Data, some data for 1</line>
        <line number="3">Data, some data for 1</line>
    </Block>
    <Block>
        <line number="4">Header, some header data for 2</line>
        <line number="5">Data some data for 2</line>
    </Block>
</lines>

cheers

  • 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-06-12T18:50:55+00:00Added an answer on June 12, 2026 at 6:50 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="kFollowing" match="line[not(substring-before(.,',')='Header')]"
      use="generate-id(preceding-sibling::line[substring-before(.,',')='Header'][1])"
      />
    
     <xsl:template match="/*">
         <lines>
           <xsl:apply-templates select="*[substring-before(.,',')='Header']"/>
         </lines>
     </xsl:template>
    
     <xsl:template match="line">
      <Block>
        <xsl:copy-of select=".|key('kFollowing', generate-id())"/>
      </Block>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <lines>
        <line number="1">Header, some header data 1</line>
        <line number="2">Data, some data for 1</line>
        <line number="3">Data, some data for 1</line>
        <line number="4">Header, some header data for 2</line>
        <line number="5">Data some data for 2</line>
    </lines>
    

    produces the wanted, correct result:

    <lines>
       <Block>
          <line number="1">Header, some header data 1</line>
          <line number="2">Data, some data for 1</line>
          <line number="3">Data, some data for 1</line>
       </Block>
       <Block>
          <line number="4">Header, some header data for 2</line>
          <line number="5">Data some data for 2</line>
       </Block>
    </lines>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
Need some help in creating function which can create folders recursively with giving path:
I need a fastest solution for transferring data from XML file to MySQL tables.
I need some help now. I would love if someone could help we with
Need some help designing a bash script for grepping IP addresses from auth.log and
I need some help from the shell-script gurus out there. I have a .txt
Need some help in parsing the file Device# Device Name Serial No. Active Policy
need some help to clarify the concept. $sql = 'SELECT * FROM tbl_post LIMIT
Need some help on this. I am clicking on a delete image which is
need some help... I need to protect all the FOLDERS in a DIRECTORY from

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.