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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:56:10+00:00 2026-05-11T09:56:10+00:00

We need to parse an XML file with XSLT into a CVS file. The

  • 0

We need to parse an XML file with XSLT into a CVS file. The code below works but only if the fields in the XML are always constant.

The fields in the our XML file will always vary. How can I change my XSLT file so that it dynamically includes in the CSV file all the fields from the XML file?

XML:

<?xml version='1.0' encoding='iso-8859-1'?> <data>     <row>         <customerID>06104539-463E-4B1A-231-34342343434</customerID>         <contactID>23434-99F2-4325-B228-6F343483469389FB</contactID>         <firstName>Jim</firstName>         <lastName>Smith</lastName>     </row>     <row>         <customerID>223434-463E-4B1A-231-A1E7EA248796</customerID>         <contactID>6675767-99F2-4325-B234328-6F83469389FB</contactID>         <specialID>112332</specialID>         <firstName>John</firstName>         <middleName>S.</middleName>         <lastName>Jones</lastName>     </row> </data> 

XSLT:

<?xml version='1.0' encoding='ISO-8859-1'?>  <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>  <xsl:template match='/'>     customerID,contactID<br/>     <xsl:for-each select='data/row'>         <xsl:value-of select='customerID'/>,<xsl:value-of select='contactID'/><br/>     </xsl:for-each> </xsl:template>  </xsl:stylesheet> 

Here is the ASP.NET file that parses the files above:

<%@ Page Language='c#' %> <%@ import Namespace='System.Xml' %> <%@ import Namespace='System.Xml.Xsl' %> <%@ import Namespace='System.Xml.XPath' %> <%@ import Namespace='System.IO' %> <%@ import Namespace='System.Text' %> <script runat='server'>      public void Page_Load(Object sender, EventArgs E) {          string xmlPath = Server.MapPath('test2.xml');         string xslPath = Server.MapPath('test2.xsl');          StreamReader reader = null;;         XmlTextReader xmlReader = null;          FileStream fs = new FileStream(xmlPath, FileMode.Open, FileAccess.Read);         reader = new StreamReader(fs,Encoding.UTF7);         xmlReader = new XmlTextReader(reader);         XPathDocument doc = new XPathDocument(xmlReader);          XslTransform xslDoc = new XslTransform();         xslDoc.Load(xslPath);          xslDoc.Transform(doc,null, Response.Output);          reader.Close();         xmlReader.Close();      }  </script> 
  • 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. 2026-05-11T09:56:11+00:00Added an answer on May 11, 2026 at 9:56 am

    I remembered doing something similar a ways back, and looking through my archive work, lo-and-behold:

    <?xml version='1.0' encoding='ISO-8859-1'?>  <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>      <xsl:key name='muench' match='/data/row/*' use='local-name()'/>      <xsl:template match='/'>         <xsl:for-each select='/data/row/*[generate-id() = generate-id(key('muench',local-name())[1])]'>             <xsl:if test='not(position()=1)'>,</xsl:if><xsl:value-of select='local-name()'/>         </xsl:for-each>         <br/>         <xsl:for-each select='/data/row'>             <xsl:variable name='current' select='.'/>             <xsl:for-each select='/data/row/*[generate-id() = generate-id(key('muench',local-name())[1])]'>                 <xsl:variable name='field' select='local-name()'/>                 <xsl:if test='not(position()=1)'>,</xsl:if><xsl:value-of select='$current/*[local-name()=$field]'/>                          </xsl:for-each>             <br/>         </xsl:for-each>     </xsl:template>  </xsl:stylesheet> 

    All hail the ugly but functional.

    I’m seriously not proud of this, but I’ve updated for your data and tested it and it works.

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

Sidebar

Related Questions

Sometimes I need to parse XML file - and only parse, and I don't
I need to parse a xml file which is practically an image of a
I have an XML file which I need to parse using PHP and send
I need parse through a file and do some processing into it. The file
Deal all, Assume I have a XML file and I need to parse it
I need to parse a XML file from the website.I have went through some
I need to parse an xml file which takes about 3 seconds, and immediately
I have an Application which contains only WebView, i need to parse a XML
I need to parse content.xml file in XMind package. File looks like this <xmap-content
file = BZ2File(SOME_FILE_PATH) p = xml.parsers.expat.ParserCreate() p.Parse(file) Here's code that tries to parse 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.