Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list complete XML document using XSLT

Tags:

xslt

What i'm looking for might seem pretty easy to understand, but i'm having a hard time making it possible.

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.

So if you know a way to recursively list all the nodes in an XML file using XSLT, thanks for the answer.

like image 835
Shadowxvii Avatar asked May 24 '26 21:05

Shadowxvii


1 Answers

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>
like image 109
Mark Costello Avatar answered May 30 '26 10:05

Mark Costello