您正在加載源XML,XSLT加載和應用彼此 有一個在.NET有限的原生支持XSLT2所以我建議使用AltovaXML庫altova xml,使用可以在那裏找到altova xml online documentaion
XSLT 2.0變換(XML到XML)
// Specify folder (AltovaXMLExamples folder)
// Check if filepath is correct for you
String strExamplesFolder = Environment.GetEnvironmentVariable("ProgramFiles") +
"\\Altova\\AltovaXML2011\\AltovaXMLExamples\\";
// Create a new AltovaXML instance and access its engines
Altova.AltovaXML.Application AltovaXML = new Altova.AltovaXML.Application();
// Use XSLT2 Engine of AltovaXML to transform simple.xml using CopyInputXSLT2.xsl
Altova.AltovaXML.IXSLT2 AltovaXMLXSLT2 = AltovaXML.XSLT2;
AltovaXMLXSLT2.InputXMLFileName = strExamplesFolder + "simple.xml";
AltovaXMLXSLT2.XSLFileName = strExamplesFolder + "CopyInputXSLT2.xsl";
AltovaXMLXSLT2.Execute(strExamplesFolder + "simpleOutputFromXML.xml");
XSLT 2.0變換(字符串到XML)
// Specify folder (AltovaXMLExamples folder)
// Check if filepath is correct for you
String strExamplesFolder = Environment.GetEnvironmentVariable("ProgramFiles") +
"\\Altova\\AltovaXML2011\\AltovaXMLExamples\\";
// Create a new AltovaXML instance and access its engines
Altova.AltovaXML.Application AltovaXML = new Altova.AltovaXML.Application();
// Use XSLT2 Engine of AltovaXML to transform input string using CopyInputXSLT2.xsl
Altova.AltovaXML.IXSLT2 AltovaXMLXSLT2 = AltovaXML.XSLT2;
AltovaXMLXSLT2.InputXMLFromText = "<?xml version='1.0'?><doc>Hello World</doc>";
AltovaXMLXSLT2.XSLFileName = strExamplesFolder + "CopyInputXSLT2.xsl";
AltovaXMLXSLT2.Execute(strExamplesFolder + "simpleOutputFromString.xml");
XSLT 2.0轉換(字符串轉換爲字符串)
// Specify folder (AltovaXMLExamples folder)
// Check if filepath is correct for you
String strExamplesFolder = Environment.GetEnvironmentVariable("ProgramFiles") +
"\\Altova\\AltovaXML2011\\AltovaXMLExamples\\";
// Create a new AltovaXML instance and access its engines
Altova.AltovaXML.Application AltovaXML = new Altova.AltovaXML.Application();
// Use XSLT2 Engine of AltovaXML to transform input string using CopyInputXSLT2.xsl
Altova.AltovaXML.IXSLT2 AltovaXMLXSLT2 = AltovaXML.XSLT2;
AltovaXMLXSLT2.InputXMLFromText = "<?xml version='1.0'?><doc>Hello World</doc>";
AltovaXMLXSLT2.XSLFileName = strExamplesFolder + "CopyInputXSLT2.xsl";
String strResult = AltovaXMLXSLT2.ExecuteAndGetResultAsString();
// Show result
MessageBox.Show("XSLT 2.0 engine answered: " + strResult);
我真的希望人們認爲downvote的問題會給出一個理由。這個網站與幫助人們學習其他任何東西一樣多,人們無法瞭解是否沒有任何反饋,而不是一個downvote。 – David
@David:完全不同意。 – Tomalak
有沒有另一種方法做什麼?你需要做什麼:使用'<?xml-stylesheet?>處理指令中指定的樣式表來處理XML?那麼是的,你必須從PI中檢索僞屬性。或者您需要使用其他預定義的樣式表來處理它? – LarsH