Reputation: 318
I want to insert the names of all of the nodes and their values into an xml. The problem that I'm having is one of the first child nodes doesn't have any values assigned to it, but it does have child nodes which have values. If I just use a wildcard then it just selects all of the child nodes on that level including the one without a value assigned to it. Is there a way to use wildcard to only select children nodes that don't have children nodes themselves?
Upvotes: 7
Views: 10495
Reputation: 5652
the predicate [not(node())]
is true for all nodes without child nodes but that includes text and comment nodes, perhaps you want [not(*)]
which is just true those nodes without element children.
<xsl:for-each select="//*[not(*)]">
<xsl:value-of select="concat(' ',name(),': ',."/>
</xsl:for-each>
therefore iterates over all the leaf elements with no element children and prints the element name and content
Upvotes: 23