understanding position() function in XSLT

Why does it skip the uneven numbers?

Because while you were at the / level, you said:

<xsl:apply-templates/>

which applies templates to all nodes children of the root node, and (due to the built-in template rules) to all of their descendants – including the text nodes that separate the <a> elements.

You will get a different result with an input of:

<?xml version="1.0" encoding="UTF-8"?>
<test><a>blah</a><a>blah</a><a>blah</a><a>blah</a></test>

or if you add an instruction to your stylesheet to:

<xsl:strip-space elements="*"/>

or if you apply templates selectively, e.g.

<xsl:apply-templates select="//a"/>

Leave a Comment