在我的C#应用程序中,我获得了word document的XML代码,并且我想使用XslCompiledTransform将其转换为HTML,就像这个答案和这一个建议的那样。
但问题是如何获取或创建要在这一行中使用的XSL样式表:
var myXslTrans = new XslCompiledTransform();
myXslTrans.Load("stylesheet.xsl"); //<- How to get this
myXslTrans.Transform("source.xml","result.html");在本教程中,它展示了如何为XML创建XSL。但是,是否有可能以编程方式对您拥有的任何XML执行此操作?
这是我得到的XML文档的示例:
<w:wordDocument xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2" xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core"
w:macrosPresent="no"
w:embeddedObjPresent="no"
w:ocxPresent="no"
xml:space="preserve">
<w:ignoreSubtree
w:val="http://schemas.microsoft.com/office/word/2003/wordml/sp2" />
<o:DocumentProperties>
<o:Author>Soft</o:Author>
<o:LastAuthor>Soft</o:LastAuthor>
<o:Revision>1</o:Revision>
<o:TotalTime>0</o:TotalTime>
<o:Created>2015-05-12T03:13:00Z</o:Created>
<o:LastSaved>2015-05-12T03:13:00Z</o:LastSaved>
<o:Pages>1</o:Pages>
<o:Words>58</o:Words>
<o:Characters>336</o:Characters>
<o:Lines>2</o:Lines>
<o:Paragraphs>1</o:Paragraphs>
<o:CharactersWithSpaces>393</o:CharactersWithSpaces>
<o:Version>12</o:Version>
</o:DocumentProperties>
<o:CustomDocumentProperties>
<o:EDOID
dt:dt="float">657360</o:EDOID>
</o:CustomDocumentProperties>
<w:fonts>
<w:defaultFonts
w:ascii="Calibri"
w:fareast="Calibri"
w:h-ansi="Calibri"
w:cs="Arial" />
<w:font
w:name="Arial">
<w:panose-1
w:val="020B0604020202020204" />
<w:charset
w:val="00" />
<w:family
w:val="Swiss" />
<w:pitch
w:val="variable" />
<w:sig
w:usb-0="E0002AFF"
w:usb-1="C0007843"
w:usb-2="00000009"
w:usb-3="00000000"
w:csb-0="000001FF"
w:csb-1="00000000" />
</w:font>
<w:font
w:name="Symbol">
<w:panose-1
w:val="05050102010706020507" />
<w:charset
w:val="02" />
<w:family
w:val="Roman" />
<w:pitch
w:val="variable" />
<w:sig
w:usb-0="00000000"
w:usb-1="10000000"
w:usb-2="00000000"
w:usb-3="00000000"
w:csb-0="80000000"
w:csb-1="00000000" />
</w:font>
<w:font
w:name="Cambria Math">
<w:panose-1
w:val="02040503050406030204" />
<w:charset
w:val="01" />
<w:family
w:val="Roman" />
<w:notTrueType />
<w:pitch
w:val="variable" />
<w:sig
w:usb-0="00000000"
w:usb-1="00000000"
w:usb-2="00000000"
w:usb-3="00000000"
w:csb-0="00000000"
w:csb-1="00000000" />
</w:font>
<w:font
w:name="Calibri">
<w:panose-1
w:val="020F0502020204030204" />
<w:charset
w:val="00" />
<w:family
w:val="Swiss" />
<w:pitch
w:val="variable" />
<w:sig
w:usb-0="E10002FF"
w:usb-1="4000ACFF"
w:usb-2="00000009"
w:usb-3="00000000"
w:csb-0="0000019F"
w:csb-1="00000000" />
</w:font>
<w:font
w:name="B Titr">
<w:panose-1
w:val="00000700000000000000" />
<w:charset
w:val="B2" />
<w:family
w:val="auto" />
<w:pitch
w:val="variable" />
<w:sig
w:usb-0="00002001"
w:usb-1="80000000"
w:usb-2="00000008"
w:usb-3="00000000"
w:csb-0="00000040"
w:csb-1="00000000" />
...
</w:body>
</w:wordDocument>更新
阅读这些注释使我相信,不可能以编程方式为任何XML文档创建XSL。
那么,我如何才能获得这个特定的XSl,这是我的问题?如果我在Microsoft word中打开这个XML,它会显示所有样式的真实word文档。我知道它也有HTML代码。所以我想让HTML代码在Microsoft word中显示相同的结果
发布于 2015-06-06 06:01:52
那么,我如何才能获得这个特定XML的XSL,这是我的问题。
使用Microsoft文件:
C:\Program \Microsoft Office\Office15\XML2WORD.XSL
发布于 2015-06-09 01:16:45
你不能在你的动态工作中使用XSL参数吗?
https://msdn.microsoft.com/en-us/library/dfktf882%28v=vs.110%29.aspx
您可以传递一些参数来切换一些xsl语句。
发布于 2015-06-08 04:35:53
最新答复:
正如我们所知道的,XSLT是一个XML文档,我们可以简单地创建一个具有xslt吸引性和扩展的xml文件。我们可以遵循这个策略。
...
XDocument document = documentBuilder.newDocument();
Element rootElement = document.createElement("xsl:stylesheet");
// adding attributes like namespaces etc...
document.appendChild(rootElement);
Element em = document.createElement("xsl:template");
em.setAttribute("match", "/");
....这只是个主意。您可以像这样设计xslt文档,并遵循正确的syntax.Apology,以避免理解第一个answer.Hope中的问题--这很有帮助
https://stackoverflow.com/questions/30543575
复制相似问题