Note that there are some explanatory texts on larger screens.

plurals
  1. POTesting for preceding-sibling and matching descendant using xsl:key
    text
    copied!<p>I have a problem that I believe I need to use grouping using xsl:key to solve, but I am at a loss as to the correct syntax. For the following XML, when I process each <code>&lt;a/&gt;</code> element I need to test to see if</p> <ol> <li><p>the element has a preceding-sibling <code>&lt;markerStart/&gt;</code> element and a descendant <code>&lt;/markerEnd&gt;</code> element with the same id. </p> <ul> <li>By "preceding-sibling" I mean that there must not be an <code>&lt;a/&gt;</code> between the current element and the <code>&lt;markerStart/&gt;</code> , so the <code>&lt;a/&gt;</code> marked <code>&lt;!-- # 5 --&gt;</code> should return false, while the <code>&lt;a/&gt;</code> marked <code>&lt;!-- # 1 --&gt;</code> and the first <code>&lt;a/&gt;</code> following the element marked <code>&lt;!-- # 2a --&gt;</code> should return true.</li> <li>By "descendant" I mean that there must not be an <code>&lt;a/&gt;</code> descendant before the <code>&lt;markerEnd/&gt;</code> , so the <code>&lt;a/&gt;</code> marked <code>&lt;!-- # 0 --&gt;</code> and the first <code>&lt;a/&gt;</code> following the element marked <code>&lt;!-- # 2b --&gt;</code> should return false.</li> </ul></li> <li><p>OR the element has a descendant <code>&lt;markerStart/&gt;</code> element and a descendant <code>&lt;/markerEnd&gt;</code> element with the same id. </p> <ul> <li>By "descendant" I mean that there must not be an <code>&lt;a/&gt;</code> descendant before the <code>&lt;markerEnd/&gt;</code>. </li> </ul></li> </ol> <p>For the following XML, I would expect the nodes marked with <code>&lt;!-- # 1 --&gt;</code>, <code>&lt;!-- # 2a --&gt;</code>, and <code>&lt;!-- # 4 --&gt;</code> to return true.</p> <pre><code>&lt;root&gt; &lt;a&gt;&lt;!-- # 0 --&gt; &lt;b&gt; &lt;c&gt; &lt;markerStart id="a1"/&gt; &lt;a&gt; &lt;!-- # 1 --&gt; &lt;b&gt; &lt;c&gt; &lt;markeEnd id="a1"/&gt; &lt;/c&gt; &lt;/b&gt; &lt;/a&gt; &lt;markerStart id="a2"/&gt;&lt;!-- # 2a --&gt; &lt;markerStart id="a3"/&gt;&lt;!-- # 2b --&gt; &lt;a&gt;&lt;!-- # 2 --&gt; &lt;b&gt; &lt;c&gt; &lt;markeEnd id="a2"/&gt; &lt;a&gt;&lt;!-- # 3 --&gt; &lt;b&gt; &lt;c&gt; &lt;markeEnd id="a3"/&gt; &lt;/c&gt; &lt;/b&gt; &lt;/a&gt; &lt;/c&gt; &lt;/b&gt; &lt;/a&gt; &lt;markerStart id="a5"/&gt; &lt;a&gt;&lt;!-- # 4 --&gt; &lt;markerStart id="a4"/&gt; &lt;b&gt; &lt;c&gt; &lt;markeEnd id="a4"/&gt; &lt;/c&gt; &lt;/b&gt; &lt;/a&gt; &lt;a&gt;&lt;!-- # 5 --&gt; &lt;b&gt; &lt;c&gt; &lt;markeEnd id="a5"/&gt; &lt;/c&gt; &lt;/b&gt; &lt;/a&gt; &lt;/c&gt; &lt;/b&gt; &lt;/a&gt; &lt;/root&gt; </code></pre> <p>I need to used XSL 1.0 for this problem. Any help is more than appreciated.</p>
 

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