Correct XSLT for XML Transform to CSV VB.NET

Posted on 2004-10-11
Last Modified: 2012-06-21
I have the following XML file:

 <?xml version="1.0" standalone="yes" ?>
- <NewDataSet>
- <Students>
  <Class>1 - A</Class>
  <First_x0020_Name>F D</First_x0020_Name>
- <Students>
  <Class>1 - A</Class>

I just want the Class and Level field output as comma delimeted. Is this the right XSLT code? I got this from a similar question on EE but my XML is slightly different:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns="">
<xsl:output method="text" version="1.0">
<xsl:template match="NewDataSet">
<xsl:for-each select="Students">
<xsl:value-of select="Class"/><xsl:text>,</xsl:text><xsl:value-of select="Level"/><xsl:text>&#013;</xsl:text>

Does anyone have some working code of an XslTransform in VB.NET? I cannot get past an error in the myxsltransform.Load(.......) command. According to gotdotnet the transform should be as easy as:

Dim xsltransform as XslTransform = new XslTransform()
xsltransform.Transform("MyDocument.xml", "TransformResult.xml")

Does this require the xml, xslt and result file to be in a certain directory?

Any help would be much appreciated.

Question by:nathanpz
  • 3

Accepted Solution

J_Mak earned 500 total points
ID: 12283214
Now that you've shown your stylesheet, I've noticed quite a few errors in it. For starters you have more than one root node which is not proper. Try this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
      <xsl:output method="text" version="1.0"/>
      <xsl:template match="/">
            <xsl:apply-templates select="NewDataSet"/>
      <xsl:template match="NewDataSet">
            <xsl:for-each select="Students">
                  <xsl:value-of select="Class"/>
                  <xsl:value-of select="Level"/>

Expert Comment

ID: 12283224
ALso, one important thing you were missing was the 'xsl' namespace prefix which I have placed in my example above. Cheers.

Author Comment

ID: 12283585
Thanks J_Mak,

My stylesheet was a mess, and that was the problem.



Expert Comment

ID: 12283589
Cheers, glad I could help.

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to parse <assert> tag in XSD1.1 using XSOM Parser? 4 60
Problem to event 3 75
API Soap Calls 4 86
PHP and Soap 3 45
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
A short film showing how OnPage and Connectwise integration works.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now