xml 如何运行 XSLT 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1590085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I run an XSLT file?
提问by Eric Anastas
Alright this seems like a stupid question but I can't figure it out. I'm writing an XSLT file to translate an XML document into an XHTML document. I've used both Visual Studio and XML Notepad 2007to preview the results of my XSLT file, but now I want to actually write out a real XHTML file so I can see how it looks in other browsers.
好吧,这似乎是一个愚蠢的问题,但我无法弄清楚。我正在编写一个 XSLT 文件来将 XML 文档转换为 XHTML 文档。我已经使用 Visual Studio 和XML Notepad 2007来预览我的 XSLT 文件的结果,但现在我想实际写出一个真正的 XHTML 文件,以便我可以看到它在其他浏览器中的外观。
Neither Visual Studio or XML NotePad have an obvious way to save the preview. Am I missing something. Obviously the file is getting created because something is being previewed, but I need to know where that file is being created or better yet choose its location.
Visual Studio 或 XML NotePad 都没有明显的方法来保存预览。我是不是错过了什么。显然,由于正在预览某些内容,因此正在创建文件,但我需要知道该文件的创建位置,或者更好地选择其位置。
采纳答案by Robert Rossney
In Visual Studio, add the XML file to a project. Open the XML file. When the file is open and its window is active, you should see, in the Properties window, that you can specify an output filename and a stylesheet. Also, you should see that the menu bar now contains an "XML" item.
在 Visual Studio 中,将 XML 文件添加到项目中。打开 XML 文件。当文件打开且其窗口处于活动状态时,您应该会在“属性”窗口中看到可以指定输出文件名和样式表。此外,您应该会看到菜单栏现在包含一个“XML”项。
If you pick "Show XSLT output" from the "XML" menu, VS will apply the specified transform to the XML file, write its output to the file you specified, and then open that file. If the file has an .xmlextension, it'll open it in a text editor window; if it has an .htmextension, it'll open it in a browser window.
如果您从“XML”菜单中选择“显示 XSLT 输出”,VS 会将指定的转换应用于 XML 文件,将其输出写入您指定的文件,然后打开该文件。如果文件有.xml扩展名,它将在文本编辑器窗口中打开它;如果它有.htm扩展名,它会在浏览器窗口中打开它。
It's a little bit clunky (it seems to me that a menu that appears and vanishes instead of being enabled/disabled is kind of hinky), but it works well enough, and it's in the tool you're already using.
它有点笨拙(在我看来,出现和消失而不是启用/禁用的菜单有点笨拙),但它运行良好,并且它在您已经使用的工具中。
回答by BryanH
You have two options:
您有两个选择:
Let the browser do it. Pass the XML with a reference to the XSLT and the browser (IE 6 or lower might have problems) will render it as (X)HTML:
<?xml-stylesheet type="text/xsl" href="http://www.example.com/my-xslt.xsl" ?>Do it server-side. Most languages have methods for accepting XSLT and XML data, then outputting (X)HTML. Here are some options:
让浏览器来做。传递带有对 XSLT 的引用的 XML,浏览器(IE 6 或更低版本可能有问题)将其呈现为 (X)HTML:
<?xml-stylesheet type="text/xsl" href="http://www.example.com/my-xslt.xsl" ?>在服务器端做。大多数语言都有接受 XSLT 和 XML 数据,然后输出 (X)HTML 的方法。以下是一些选项:
回答by Tomalak
回答by Sumit Kishore
For a one-off task where you do not want to go thru the pain of an install, you could probably use https://www.freeformatter.com/xsl-transformer.html. I'l disclaim that I have not used this site much.
对于您不想经历安装痛苦的一次性任务,您可能可以使用https://www.freeformatter.com/xsl-transformer.html。我声明我没有经常使用这个网站。
回答by Alex Pour
There are many third-party software. One of them is "Oxygen XML Editor". In this software, simply:
有很多第三方软件。其中之一是“Oxygen XML Editor”。在这个软件中,只需:
- Open your .xml
- Open your .xslt
- Click "run" in the toolbar for see results( output will be in the right panel).
- If you want to save result, R-click on result in right panel and choose "save ..."
- If you have problem, may be you need change processing in toolbar: "Xalan,Saxon,Saxon-HE,saxon-PE,..."
- 打开你的 .xml
- 打开你的 .xslt
- 单击工具栏中的“运行”以查看结果(输出将在右侧面板中)。
- 如果要保存结果,请在右侧面板中右键单击结果并选择“保存...”
- 如果您遇到问题,可能需要在工具栏中进行更改处理:“Xalan,Saxon,Saxon-HE,saxon-PE,...”


