Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Edit</strong>: In my initial reply (below) I thought that the value of the <code>select</code> attribute was required to be a pattern and now I see that I was misled by the spec.</p> <p>In this case, the reported behavior is most likely a bug.</p> <p>@Jahangir, congratulations for discovering a bug in at least three XSLT 2.0 processors.</p> <hr> <p><strong>The W3C XSLT 2.0 spec says</strong> (about the <code>select</code> attribute of <code>xsl:for-each-group</code>):</p> <blockquote> <p>"•If the group-starting-with attribute is present, then its value must be a pattern."</p> </blockquote> <p>And the rules for pattern allow only the <code>child::</code> or <code>attribute::</code> axes to be used in the pattern. </p> <p><strong>Therefore, <code>descendant::*</code> is not allowed as a pattern</strong>. I guess that the XSLT processor treats this as "recoverable error" and takes its own action as recovery.</p> <p>The solution is to put the first <code>milestone</code> element in its proper place as the immediate following sibling of <code>div</code>, and change the <code>select attribute of</code>xsl:for-each-group<code>to:</code>div/*`:</p> <pre><code>&lt;text&gt; &lt;body&gt; &lt;div&gt; &lt;milestone unit="fragment"/&gt; &lt;p&gt;First line text in FIRST fragment&lt;/p&gt; &lt;p&gt;Second line &lt;seg&gt;text in FIRST&lt;/seg&gt; fragment &lt;/p&gt; &lt;p&gt;Third line text in FIRST fragment&lt;/p&gt; &lt;milestone unit="fragment"/&gt; &lt;p&gt;First line text in SECOND fragment&lt;/p&gt; &lt;p&gt;Second line &lt;seg&gt;text in SECOND &lt;/seg&gt; fragment &lt;/p&gt; &lt;p&gt;Third line text in SECOND fragment&lt;/p&gt; &lt;milestone unit="fragment"/&gt; &lt;p&gt;First line text in THIRD fragment&lt;/p&gt; &lt;p&gt;Second line &lt;seg&gt;text in THIRD &lt;/seg&gt; fragment &lt;/p&gt; &lt;p&gt;Third line text in THIRD fragment&lt;/p&gt; &lt;/div&gt; &lt;/body&gt; &lt;/text&gt; </code></pre> <p>and:</p> <pre><code>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"&gt; &lt;xsl:output method="html" name="html" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" include-content-type="no"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="body"&gt; &lt;xsl:for-each-group select="div/*" group-starting-with="milestone[@unit='fragment']"&gt; &lt;xsl:variable name="currFragNumber"&gt; &lt;xsl:number count="milestone[@unit='fragment']" level="any" from="text"/&gt; &lt;/xsl:variable&gt; &lt;xsl:result-document href="{$currFragNumber}.html" format="html"&gt; &lt;xsl:apply-templates select="current-group()" /&gt; &lt;/xsl:result-document&gt; &lt;/xsl:for-each-group&gt; &lt;/xsl:template&gt; &lt;xsl:template match="p"&gt; &lt;p&gt; &lt;xsl:apply-templates/&gt; &lt;/p&gt; &lt;/xsl:template&gt; &lt;xsl:template match="seg"&gt; &lt;span&gt; &lt;xsl:apply-templates/&gt; &lt;/span&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