Reputation: 17
Can someone explain the below syntax of XSL
<xsl:template match="@*|node()[not(self::*)]">
<xsl:element name="{local-name()}">
Upvotes: 0
Views: 46
Reputation: 163262
match="@*|node()[not(self::*)]"
@*
- the template matches all attribute nodes
node()[XXX]
- the template matches elements, text nodes, comments, and processing instructions, provided that the predicate XXX is true
self::*
- if the context node is an element, this selects the element, otherwise it selects nothing
not(self::*)
- is true if self::*
selects nothing, that is, if the context node is not an element.
So the code matches all attributes, text nodes, comments, and processing instructions
It could also be written
match="@* | text() | comment() | processing-instruction()"
The next line
<xsl:element name="{local-name()}"/>
Creates an element whose name is the same as the local name of the context item. This is fine if the context item is an attribute or processing instruction, but it will cause a dynamic error if the context item is a comment or text node, because those nodes have no local-name.
So the code is buggy: it doesn't make sense to write a template rule that matches comments and text nodes and then fails if it encounters one.
Upvotes: 1
Reputation: 1816
You are creating elements with all node() names and attributes not remaining elements:
Note: you are not matching elemetns
Upvotes: 0