如何使用 XSLT 列出完整的 XML 文档 [英] How to list complete XML document using XSLT
问题描述
我正在寻找的东西可能看起来很容易理解,但我很难让它成为可能.
What i'm looking for might seem pretty easy to understand, but i'm having a hard time making it possible.
我希望能够使用 XSLT 将 XML 文件的内容放在 HTML 页面上.问题是,我想递归地列出所有节点名称(而不是内容).此外,我必须考虑这样一个事实,即我无法预测节点的名称.
I want to be able to put the content of an XML file on an HTML page using XSLT. The thing is, i want to list all the nodes name (not the content), recursively. Also, i have to consider the fact that i can't predict what are going to be the names of the nodes.
因此,如果您知道一种使用 XSLT 递归列出 XML 文件中所有节点的方法,感谢您的回答.
So if you know a way to recursively list all the nodes in an XML file using XSLT, thanks for the answer.
推荐答案
由于您要求的是节点名称而不是内容,因此您不需要递归进行,这是最简单的方法.
Since you asked for the node names and not the content, you don't need to do it recursively, this is the simplest way.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:for-each select="//node()">
<xsl:value-of select="name()"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
这篇关于如何使用 XSLT 列出完整的 XML 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!