14

Does anyone know of a list of XSLT instructions/functions that change the context node?

For example, instruction like for-each is one of them.

Emiliano Poggi
  • 24,390
  • 8
  • 55
  • 67
Pacerier
  • 86,231
  • 106
  • 366
  • 634

2 Answers2

16

The obvious XSLT 2.0 instructions that change the context are for-each, apply-templates, for-each-group, and analyze-string. But there's also, for example, xsl:sort and xsl:key.

In XPath, the operators / and [] change the context. There are no functions that change the context.

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
Michael Kay
  • 156,231
  • 11
  • 92
  • 164
3

There are only two things in XSLT 1.0 that change the context and neither of them are functions. These are:

<xsl:apply-templates select='some-test'/>

(which will lead to the selected nodes being processed, each one becoming the context node as it is processed)

and

<xsl:for-each select='some-test'/>

In XSLT 2.0, you also have

<xsl:for-each-group/>

(which sets the context node in slightly more complex way than xsl:apply-templates and xsl:for-each

Nic Gibson
  • 7,051
  • 4
  • 31
  • 40
  • 1
    apply-templates doesn't change the context node within the current template, it goes to a different template. As far as I know, xsl:for-each is the only one that can change the meaning of `.` inside a template. – Flynn1179 Aug 05 '11 at 12:33
  • 2
    Strictly speaking, yes. `xsl:apply-templates` itself does not change the context. It selects nodes for processing. The processing template itself sets the current node. However, it does lead to the context changing which was the point I was making :) – Nic Gibson Aug 05 '11 at 13:05