Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Off the top of my head, I would first use a key that matches entries by their ancestor table:</p> <pre><code>&lt;xsl:key name="moreRowsEntriesByTable" match="entry[@morerows]" use="generate-id(ancestor::table[1])" /&gt; </code></pre> <p>Hopefully you can use that to narrow down the set of nodes that you have to process in XPath. But I confess I haven't really understood the condition you're trying to filter by, so I'm not positive that the above is applicable.</p> <h2>Update</h2> <p>Re: "I can't figure out how to include my XPath condition and get a result." I often get frustrated in XSLT 1.0 at the awkwardness of trying to combine a key with a preceding:: or following:: axis. It can't be done succinctly.</p> <p>You could work it in by inserting the following predicate where needed:</p> <pre><code>[count(key('moreRowsEntriesByTable', $table-id) | .) = count(key('moreRowsEntriesByTable', $table-id)] </code></pre> <p>where $table-id is the id of the current() node's ancestor table:</p> <pre><code>&lt;xsl:variable name="table-id" select="generate-id(ancestor::table[1])" /&gt; </code></pre> <p>But that may be slower than not using a key at all:</p> <pre><code>[generate-id(ancestor::table[1]) = $table-id] </code></pre> <p>You could attach this predicate to each <code>entry</code> node test in you XPath expression. But again, I'm not sure it would help with performance.</p> <h2>Alternative</h2> <p>Instead, I would suggest a two-stage transformation. Does your processing context allow that? For that, you can either run two stylesheets, with the output of the first piped to the input of the second; or use the common <code>node-set()</code> extension function to convert the output of one template to a node set that can serve as input to another template.</p> <p>In the first transformation, you could add attributes to each table cell to help with the computation, such as...</p> <pre><code>@row -- row number of this entry in current table (position() of parent::row) @index -- position of this entry among siblings in the parent::row, taking into account their colspans if necessary. @table-id -- generate-id(ancestor::table[1]) </code></pre> <p>The idea would be amortization (if I'm applying that term correctly)... If these values are computed once per entry, in the first stage, instead of many times, in the complicated XPath expression, that could make things quite a bit faster. Maybe there are other attributes that would be more helpful.</p> <p>You could remove (not copy) these helper attributes in the second transformation.</p> <p>This is a sketchy suggestion, but maybe it will help point toward a good solution.</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