Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Correct XSLT for XML Transform to CSV VB.NET

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

 <?xml version="1.0" standalone="yes" ?>
- <NewDataSet>
- <Students>
  <Class>1 - A</Class>
  <Last_x0020_Name>Gilbert</Last_x0020_Name>
  <First_x0020_Name>F D</First_x0020_Name>
  <New_x0020_Score>21</New_x0020_Score>
  <Level>H</Level>
  <MaxScore>30</MaxScore>
  <NewNumScore>21</NewNumScore>
  <PercentDec>0.7</PercentDec>
  </Students>
- <Students>
  <Class>1 - A</Class>
  <Last_x0020_Name>Johnson</Last_x0020_Name>
  <First_x0020_Name>F</First_x0020_Name>
  <New_x0020_Score>18</New_x0020_Score>
  <Level>H</Level>
  <MaxScore>30</MaxScore>
  <NewNumScore>18</NewNumScore>
  <PercentDec>0.6</PercentDec>
 </Students>
</NewDataSet>


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="http://www.w3.org/1999/XSL/Transform">
<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>
</xsl:for-each>
</xsl:template>
</xsl:output>
</xsl:stylesheet>

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.Load("favorite.xsl")
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.


0
Comment
Question by:nathanpz
  • 3
4 Comments
 
LVL 7

Accepted Solution

by:
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="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="text" version="1.0"/>
      <xsl:template match="/">
            <xsl:apply-templates select="NewDataSet"/>
      </xsl:template>
      <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/>
            </xsl:for-each>
      </xsl:template>
</xsl:stylesheet>
0
 
LVL 7

Expert Comment

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

Author Comment

by:nathanpz
ID: 12283585
Thanks J_Mak,

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

Ta.

0
 
LVL 7

Expert Comment

by:J_Mak
ID: 12283589
Cheers, glad I could help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 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