1

Can anyone tell me the meaning of the below template match

<xsl:template match="*[not(*)]">

and

<xsl:template match="*(*)">

What i guessed is , the first template match will be applied for all the element nodes which dont have any child elements

and second match applies for the elements with child elements Thanks

sreevathsa a
  • 149
  • 13

2 Answers2

2

* is used to match any element. Where you have square brackets, this represents a condition to be checked on that element. In this case not(*) is checking that there are no child elements.

Therefore <xsl:template match="*[not(*)]"> will match elements that have no child elements. Thus it it would match this (as Bob is a text node, not an element)

<Name>Bob</Name>

And this (as type is an attribute, not an element).

<Name type="A" />

But it would not match this (as Name has the child element FirstName)

<Name><FirstName>Bob</FirstName></Name>

The second pattern <xsl:template match="*(*)"> is not actually valid syntax.

If you were trying to match elements which did have child elements, you would do this:

<xsl:template match="*[*]">
Tim C
  • 70,053
  • 14
  • 74
  • 93
0
<xsl:template match="*[not(*)]">

It means element that doesn't have any element under it.

<xsl:template match="*(*)">

This looks to be syntactically wrong. Because you should use [] there. Then it would mean select any element that has element(s) under it.

Here element is a tag <tag> not text node or attribute. Hope it answers.

Rookie Programmer Aravind
  • 11,952
  • 23
  • 81
  • 114