I have an XML document that is generated from database information. I also have a separate XMLT file. I need to use VB.NET to insert the XSL link into the XML document. I am getting it inserted, but it's inserting into the wrong place. I need it in the header but it's putting it after the root node.

Here's the code I'm using to insert the xml-stylsheet processing instruction:

```
Dim fiFilePath As String = Me.CSFileName
Dim xmlCs As XmlDocument = Nothing
Try
    xmlCs = New XmlDocument()
    xmlCs.Load(fiFilePath)
    ' update the XSLT path as per the 'newStyleSheetPath' argument
    xmlCs.DocumentElement.PrependChild(xmlCs.CreateProcessingInstruction("xml-stylesheet", String.Format("type={0}text/xsl{1} href={2}{3}{4}", Chr(34), Chr(34), Chr(34), newStylesheetPath, Chr(34))))
    'Save the created document
    xmlCs.Save(fiFilePath)
Catch ex As Exception
    xmlCs = Nothing
    fiFilePath = Nothing
    Throw ex
End Try

```

This is what that code is outputting:

```
<DocumentRoot>
  <?xml-stylesheet type="text/xsl" href="APSCS.xsl"?>
  <realmCode code="US" />

```

But it needs to be:

```
<?xml-stylesheet type="text/xsl" href="APSCS.xsl"?>
<DocumentRoot>
  <realmCode code="US" />

```

This is all part of an export where the XSLT is packaged with the XML, so if someone opens the XML, it appears in the browser using the XSLT file sent with it.