Link to home
Start Free TrialLog in
Avatar of philipHaugaard
philipHaugaard

asked on

XslTransform is removeing tag

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
ASKER CERTIFIED SOLUTION
Avatar of b1xml2
b1xml2
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of philipHaugaard
philipHaugaard

ASKER

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
no problem =)
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
lol =)