是否可以使用 XSLT 对 XML 文档进行颜色编码和格式化?
以前有人这样做过吗? 是否可以编写一个 XSLT 将 XML 文档转换为颜色编码、格式化的 HTML?
Has this ever been done before?
Is it possible to write an XSLT that will turn an XML document into color-coded, formatted, HTML?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看这个带有语法突出显示的 XML 到 HTML 逐字格式化程序
Take a look at this XML to HTML Verbatim Formatter with Syntax Highlighting
XMLSPectrum.xsl(在 GitHub 上)是执行此操作的众多 XSLT 样式表之一 - 但这个工具专门针对 XSLT 2.0 的额外需求。
使用 XSLT 2.0,许多编程逻辑都可以位于 XPath 2.0 表达式内。因此,该产品的重点是 XPath 的格式化和着色,同时还要确保正确呈现 XSLT 指令。来自浏览器的示例屏幕截图:
因为 XSLT 输入被解析为文本,所以任何现有的缩进和行 -默认情况下会保留提要 - 即使在属性中也是如此(示例没有格式,因此设置了缩进选项)。与通常的 XML 格式一样,所有属性及其内容都是垂直对齐的
XMLSPectrum.xsl (on GitHub) is one of a number of XSLT stylesheets that do this - but this tool is specially for the additional demands of XSLT 2.0.
With XSLT 2.0, much of the programming logic can be within the XPath 2.0 expressions. So the emphasis for this product was the formatting and colorising of XPath - while also ensuring XSLT instructions are rendered properly also. A sample screenshot from a browser:
Because the XSLT input is parsed as text, any existing indentation and line-feeds are preserved by default - even in attributes (the sample had no formatting so the indent option was set). As well as the usual XML formatting, all attributes and their contents are vertically aligned