作成した XML ドキュメントに XSLT スタイルシートを添付したいと考えています。
XML ドキュメント コード
XML ドキュメントは、次のコードを使用して作成されます。
Private Sub CreateXML(ByVal ds1 As StatusProd.dsAssemblies, ByVal ReportName As String)
ReportName = ReportName.Replace(".rdlc", "")
Dim w As New XmlTextWriter(ReportName & ".xml", System.Text.Encoding.UTF8)
w.WriteStartDocument(True) 'Start document
w.Formatting = Formatting.Indented
w.Indentation = 2
w.WriteStartElement("Table") 'Start table
For Each row As DataRow In ds1.Tables(0).Rows
w.WriteStartElement("Assemblies")
w.WriteStartElement("MachineNo")
w.WriteString(row(0))
w.WriteEndElement()
w.WriteStartElement("Description")
w.WriteString(row(1))
w.WriteEndElement()
w.WriteStartElement("Client")
w.WriteString(row(2))
w.WriteEndElement()
w.WriteStartElement("DateTransfer")
w.WriteString(row(4))
w.WriteEndElement()
w.WriteEndElement()
Next
w.WriteEndElement() 'End table
w.WriteEndDocument() 'End document
w.Close()
End Sub
XSLT XML への追加
XML ドキュメント クリエータの最後に次のコードを追加しようとしましたが、次のエラーが発生しました: 指定された場所にノードを挿入できませんでした。
'Append XSL to XML
Dim doc As New XmlDocument
doc.Load("rptStatusProd.xml")
doc.PrependChild(doc.CreateProcessingInstruction("xml-stylesheet", "type='text/xsl' href='Fetch.xslt'"))
doc.Save(w)
XML ドキュメントの最終結果
次のように、XML ドキュメントの 2 行目に処理命令を追加したいと考えています。
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="Fetch.xslt"?>
私はこれを再現しようとしてきました: