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 8920505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:17:12+00:00 2026-06-15T06:17:12+00:00

I am trying to make a csv from an xml file of the form:

  • 0

I am trying to make a csv from an xml file of the form:

    <?xml version="1.0" encoding="UTF-8"?>
    <Envelope>
        <Header>
            <env:MessageSentDateTime>2012-09-19T09:50:04Z</env:MessageSentDateTime>
            <env:MessageSequenceNumber>856432</env:MessageSequenceNumber>
        </Header>
        <Body>
            <Data>
                <Data:ID>
                    <Data:AODB>9346280</Data:AODB>
                    <Data:Ref>
                        <common:Code>HJ</common:Code>
                        <common:num>8113</common:num>
                    </Data:Ref>
                 </Data:ID>
                 ... Continues like this, no set number of nodes, parts or AnotherParts
         </Body>
         Second message starting with <Header> ending with </Body>, 
         will be more than 2 in practice
    </Envelope>

I want to put a newline in the csv file at the /Body tag since this indicates a new message. There will be a mixture of messages so different numbers of nodes, different numbers of parts and no consistent end node in the Body part. In addition, there will be nodes that do not contain any text but I still want a comma there.

So far I have:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="text"/>
        <xsl:strip-space elements="*"/>

        <xsl:template match="*[not(*)]">
            <xsl:value-of select="normalize-space(.)"/>
            <xsl:text>,</xsl:text>
        </xsl:template>

        <xsl:template match="Body[last()]">
            <xsl:value-of select="normalize-space(.)"/>
            <xsl:text>&#10;</xsl:text>
        </xsl:template>
    </xsl:stylesheet>

It also adds a comma after the last piece of information in Body. I’d like to replace that comma with a newline, is there a simple way to do this?

Regards,
David

  • 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-15T06:17:14+00:00Added an answer on June 15, 2026 at 6:17 am

    My specifications changed slightly, needed the node path as well as the value in order to make each entry unique. This is the code I used to solve my problem:

        <?xml version="1.0" encoding="utf-8"?>
        <xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="text"></xsl:output>
        <xsl:strip-space elements="*"/>
    
        <xsl:template match="*[*]">
            <xsl:param name="elementNames" select="''"/>
            <xsl:apply-templates select="*">
                <xsl:with-param name="elementNames">
                    <xsl:copy-of select="$elementNames"/>
                    <xsl:value-of select="replace(name(.), ':', '.')"/>
                    <xsl:text>_</xsl:text>
                </xsl:with-param>
            </xsl:apply-templates>
         </xsl:template>
    
         <xsl:template match="*[not (*)]">
             <xsl:param name="elementNames" select="''"/>
             <xsl:copy-of select="$elementNames"/>
             <xsl:value-of select="replace(name(.), ':', '.')"/>
             <xsl:value-of select="name()"/>,<xsl:apply-templates select="current()/text()"/>
             <xsl:text>&#10;</xsl:text>
         </xsl:template>
    
         <xsl:template match="/*">
              <xsl:apply-templates select="*"/>
         </xsl:template> 
         </xsl:stylesheet>
    

    Thank you to everybody who looked and tried to help.

    Regards,
    David

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a graph with highcharts from a csv file. Following is
I am trying to make a website that reads from a csv file and
I am trying to make a csv file from a textbox and then send
I am trying to make a cURL call to download a CSV file and
I am trying to download a CSV file using HttpResponse to make sure that
I am trying to insert data from a csv file into mysql using BigDump.
I can't create an utf-8 csv file in Python. I'm trying to read it's
Possible Duplicate: reading a specific file from sdcard in android I'm trying to make
I'm streaming data from a CSV file and trying to import it to SQL
I'm trying to extract a small amount of data from an XML file into

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.