I just wrote an XSLT that did not work at first.
I had to rename all children of <Recordset> to <C>:
<?xml version="1.0" encoding="utf-8"?>
<Record>
<Recordset>
<company>102</company>
<store>1801</store>
....
</Recordset>
<Recordset>
....
</Recordset>
</Record>
I used the following XSLT:
<xsl:template match="Record/Recordset/child::*">
<xsl:element name="C">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
It works and renames all children of <Recordset> to <C>.
But first my match in the template looked like this:
<xsl:template match="Record/Recordset/child::node()">
My idea was that every child of <Recordset> is a node, thus node() would be appropriate.
It worked too but it inserted an extra <C/> for each child.
What’s the difference between child::node() and child::*?
child::node()matches any node that’s not an attribute node, namespace node, or document node. That means that it does match processing instructions, comments, and text nodes.child::*matches only elements.See section 5.5.3 of the spec:
Update: Michael’s answer inspired the following stylesheet. Use it to test the types of nodes as they’re processed:
Modify what’s matched/selected to test other patterns. For example, the following input:
Produces the following output:
Special thanks to this page for getting me started on the node-type tests. (It’s especially fitting that one of Michael’s answers from over six years ago appears there, too.)