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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:01:42+00:00 2026-06-17T08:01:42+00:00

I have an xml file with this structure: <a> <b attribute=54 name=Bob … >

  • 0

I have an xml file with this structure:

<a>
    <b attribute="54" name="Bob" ... >
        <c name="Foo" stuff="89" attr="First line&#xA;Second line" ... />
        <c name="Bar" stuff="23" attr="Blahs" ... />
        ...
    </b>
    ...
</a>

I would like to get this data in a csv file looking something like:

b_attribute, b_name, ... , c1_name, c1_stuff, c1_attr ... , c2_name, c2_stuff, c2_attr ... 
"54", "Bob", ..., "Foo", "89", "First line&#xA;Second line", ..., "Bar", "23", "Blahs", ...

some of the tags’ values may contain html commas and quotes.

  • 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-17T08:01:43+00:00Added an answer on June 17, 2026 at 8:01 am

    How’s this:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
                    xmlns:templates="csv-templates" xmlns:values="csv-values"
    >
      <templates:header />
      <templates:value />
      <xsl:variable name="header" select="document('')//templates:header" />
      <xsl:variable name="value" select="document('')//templates:value" />
    
      <values:substitutions>
        <sub from="&quot;" to="&quot;quot;" />
        <sub from="," to="&quot;#x2C;" />
        <sub from="&#xA;" to="&amp;#xA;" />
      </values:substitutions>
      <xsl:variable name="substitutions" select="document('')//values:substitutions" />
    
      <xsl:output method="text" />
    
      <xsl:template match="text()" />
    
      <xsl:template match="/">
        <xsl:apply-templates select="*/*" mode="headers">
          <xsl:sort data-type="number" select="count(*)" order="descending"/>
        </xsl:apply-templates>
        <xsl:variable name="headerCount">
          <xsl:apply-templates select="*/*" mode="countAttributes">
            <xsl:sort data-type="number" select="count(*)" order="descending"/>
          </xsl:apply-templates>
        </xsl:variable>
    
        <xsl:apply-templates select="*/*">
          <xsl:with-param name="headerCount" select="$headerCount" />
        </xsl:apply-templates>
      </xsl:template>
    
      <xsl:template match="/*/*">
        <xsl:param name="headerCount" />
        <xsl:text>&#xA;</xsl:text>
        <xsl:call-template name="CommaList">
          <xsl:with-param name="items" select=".//@*"/>
          <xsl:with-param name="type" select="$value" />
          <xsl:with-param name="minCount" select="$headerCount" />
        </xsl:call-template>
      </xsl:template>
    
      <xsl:template match="/*/*" mode="headers">
        <xsl:if test="position() = 1">
          <xsl:call-template name="CommaList">
            <xsl:with-param name="items" select=".//@*"/>
            <xsl:with-param name="type" select="$header" />
          </xsl:call-template>
        </xsl:if>
      </xsl:template>
    
      <xsl:template match="/*/*" mode="countAttributes">
        <xsl:if test="position() = 1">
          <xsl:value-of select="count(.//@*)"/>
        </xsl:if>
      </xsl:template>
    
      <xsl:template match="templates:header" priority="2">
        <xsl:param name="item" />
        <xsl:variable name="index">
          <xsl:if test="count($item/ancestor::*) > 2">
            <xsl:value-of select="count($item/../preceding-sibling::*) + 1"/>
          </xsl:if>
        </xsl:variable>
        <xsl:value-of select="concat(local-name($item/..), $index, '_', local-name($item))"/>
      </xsl:template>
    
      <xsl:template match="templates:value" priority="2">
        <xsl:param name="item" />
        <xsl:if test="normalize-space($item)">
          <xsl:text>"</xsl:text>
          <xsl:call-template name="escape">
            <xsl:with-param name="value" select="$item" />
          </xsl:call-template>
          <xsl:text>"</xsl:text>
        </xsl:if>
      </xsl:template>
    
      <xsl:template name="CommaList">
        <xsl:param name="items" />
        <xsl:param name="type" />
        <xsl:param name="minCount" select="0" />
    
        <xsl:apply-templates select="$type">
          <xsl:with-param name="item" select="$items[1]" />
        </xsl:apply-templates>
    
        <xsl:variable name="remainder" select="$items[position() > 1]" />
        <xsl:if test="$remainder or $minCount > 1">
          <xsl:text>, </xsl:text>
          <xsl:call-template name="CommaList">
            <xsl:with-param name="items" select="$remainder" />
            <xsl:with-param name="type" select="$type" />
            <xsl:with-param name="minCount" select="$minCount - 1" />
          </xsl:call-template>
        </xsl:if>
      </xsl:template>
    
      <xsl:template name="escape">
        <xsl:param name="value"/>
    
        <xsl:variable name="foundToEscape" select="$substitutions/sub[contains($value, @from)]" />
    
        <xsl:choose>
          <xsl:when test="$foundToEscape">
            <xsl:call-template name="escape">
              <xsl:with-param name="value" select="substring-before($value, $foundToEscape/@from)" />
            </xsl:call-template>
            <xsl:value-of select="$foundToEscape/@to"/>
            <xsl:call-template name="escape">
              <xsl:with-param name="value" select="substring-after($value, $foundToEscape/@from)" />
            </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$value"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:template>
    </xsl:stylesheet>
    

    Additional substitution rules can be added by adding additional <sub> elements to the <values:substitutions> element.

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

Sidebar

Related Questions

I have an xml file with a structure like this <display> <service> <URL></URL> <name></name>
ich have a xml file with the following structure: <layer1 name=this is layer1> <messages>
I have an XML file of the following structure <Root> <Child Name=First> <Data Name=a
I have an xml file that contains a structure.. In this structure, I have
I have a XML file like this <?xml version=1.0 encoding=utf-8?> <Survey Name=Aerosmith's Survey Id=S2
I have an xml file like this: <result> <customer> <id>1</id> <name>A</name> </customer> <customer> <id>2</id>
I have an XML file of this Kind : <data> <First id=FirstOne> <lines id=Lines>
I have this xml file which has text init. i.e Hi my name is
I have an xml mapping file that looks something like this <colourMappings> <model name=modelX>
need to convert an xml file having a tag(dynamicVariable) that has an attribute(name).This xml

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.