Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Recursion usually works pretty well with problems like this.</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="text" media-type="text/plain" /&gt; &lt;xsl:template name="count-previous-but-not-with-my-name"&gt; &lt;xsl:param name="nodes" /&gt; &lt;xsl:param name="count" select="0" /&gt; &lt;xsl:choose&gt; &lt;xsl:when test="count($nodes) = 0"&gt; &lt;xsl:value-of select="$count" /&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:variable name="last-name" select="$nodes[last()]/@name" /&gt; &lt;xsl:variable name="nodes-before-me-without-my-name" select="$nodes[position() &amp;lt; last() and @name != $last-name]" /&gt; &lt;xsl:call-template name="count-previous-but-not-with-my-name"&gt; &lt;xsl:with-param name="nodes" select="$nodes-before-me-without-my-name" /&gt; &lt;xsl:with-param name="count" select="$count + 1" /&gt; &lt;/xsl:call-template&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/"&gt; &lt;xsl:for-each select="//ROLEACTIONINFO/ROLE"&gt; &lt;xsl:variable name="role" select="current()" /&gt; &lt;xsl:variable name="my-pos" select="position()" /&gt; &lt;xsl:value-of select="current()/@name" /&gt;&lt;xsl:text&gt; &lt;/xsl:text&gt; &lt;xsl:call-template name="count-previous-but-not-with-my-name"&gt; &lt;xsl:with-param name="nodes" select="$role/../ROLE[position() &amp;lt;= $my-pos]" /&gt; &lt;/xsl:call-template&gt; &lt;xsl:text&gt;&amp;#10;&lt;/xsl:text&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload