?
Solved

XslTransform is removeing tag

Posted on 2005-04-15
5
Medium Priority
?
183 Views
Last Modified: 2010-04-23
Hello Experts
first time i try to use this so here goes:

I have made a tiny program in VB.net that takes an XML file and apply an XSTL to that file.
the problem is that whenever i try to run the XSLT that looks like:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="xsi">
      <xsl:output method="xml" encoding="UTF-8" doctype-system="sample.dtd"/>
      <xsl:template match="/data">
            <data>
                  <xsl:for-each select="dbo.Proever">
                        <dbo.Proeve>
                              <xsl:for-each select="@proeveID">
                                    <proeveID>
                                          <xsl:value-of select="."/>
                                    </proeveID>
......snip
                                          <xsl:for-each select="@metaGruppe">
                                                <metaGruppe>
                                                      <xsl:value-of select="."/>
                                                </metaGruppe>
                                          </xsl:for-each>
                                    </dbo.RNR>
                              </xsl:for-each>
                        </dbo.Proeve>
                  </xsl:for-each>
            </data>
      </xsl:template>
</xsl:stylesheet>

its a rather long xslt file so i have not pasted it all. the problem is that after running this code:

    Public Sub ReadTransformWrite()
        Try
            Dim xpathdocument As New XPathDocument(OpenFileDialog1.FileName)

            Dim xslt As New XslTransform
            xslt.Load(OpenFileDialog2.FileName)

            Dim writer As New XmlTextWriter(SaveFileDialog1.FileName, System.Text.Encoding.UTF8)
            writer.Formatting = Formatting.Indented

            xslt.Transform(xpathdocument, Nothing, writer, Nothing)
            writer.Close()
            Label1.Text = "Processing complete"
        Catch e As Exception
            Label1.Text = "Processing Aborted due to Error"
        End Try
    End Sub

the program output looks like this:

<data>
  <dbo.Proeve>
    <proeveID>1498</proeveID>
    <Analysenavn>C'-funktion, C3, C4, C5, C3 nephr.fact.</Analysenavn>
    <Artikelnr>48579</Artikelnr>

and it have not written out the the <?xml version="1.0" encoding="UTF-8"?> that the output should have started with.

i am quite boggled by this and cant find out why this is so. i could ofcource rewrite the output file and just hardcode the <?xml version="1.0" encoding="UTF-8"?> at the top but i would like to make the program generic so its really not an option.

Thank you for your time
Philip
0
Comment
Question by:philipHaugaard
  • 3
  • 2
5 Comments
 
LVL 23

Accepted Solution

by:
b1xml2 earned 2000 total points
ID: 13792609
Dim xpathdocument As New XPathDocument(OpenFileDialog1.FileName)
Dim xslt As New XslTransform
xslt.Load(OpenFileDialog2.FileName)
Dim writer As New XmlTextWriter(SaveFileDialog1.FileName, System.Text.Encoding.UTF8)
writer.Formatting = Formatting.Indented
writer.WriteProcessingInstruction("xml","version='1.0' encoding='UTF-8'")
xslt.Transform(xpathdocument, Nothing, writer, Nothing)
0
 

Author Comment

by:philipHaugaard
ID: 13796519
I cant belive i didt look closer at the writer. I spent hours looking at the transformer.
well ill be back to work monday and give the solution a try. Ill write if it worked

Thanks for your time
Philip
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13796814
no problem =)
0
 

Author Comment

by:philipHaugaard
ID: 13805934
Works just like it should :)
Not really in my opinion the work of the writer but i cant really blame the expert that came with the solution for that ;)

Best Regards
Philip
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13805952
lol =)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

830 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