0

How to select all nodes without inner elements and without attributes in .xml with unknown structure?

Yuliia Ashomok
  • 8,336
  • 2
  • 60
  • 69
  • 2
    start here: http://stackoverflow.com/questions/3926589/how-to-select-all-leaf-nodes-using-xpath-expression – forty-two Jun 17 '14 at 12:51

1 Answers1

1

XPATH expression to find elements without subelements nor attributes is: //[not(|@*)] You will get only elements with text(). Code that gets names of those elements is below:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <xsl:template match="/">
 <xsl:apply-templates select="//*[not(*|@*)]"/>
 </xsl:template>

<xsl:template match="*|@*">
<xsl:value-of select="name()"/><xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
mg_kedzie
  • 337
  • 1
  • 9