Note that there are some explanatory texts on larger screens.

plurals
  1. POXML to table, how to get position() of context node to the specified ancestor(s)
    primarykey
    data
    text
    <p>I have such xml:</p> <pre><code>&lt;A1&gt; &lt;B1&gt; &lt;C1&gt; &lt;C2&gt; &lt;C3&gt; &lt;/B1&gt; &lt;B2&gt; &lt;C4&gt; &lt;C5&gt; &lt;C6&gt; &lt;/B2&gt; &lt;/A1&gt; &lt;A2&gt; &lt;B3&gt; &lt;C7&gt; &lt;C8&gt; &lt;C9&gt; &lt;/B3&gt; &lt;B4&gt; &lt;C10&gt; &lt;C11&gt; &lt;C12&gt; &lt;/B4&gt; &lt;/A2&gt; </code></pre> <p>I need to transform it to table with nested rows:</p> <pre><code>&lt;table border="yes"&gt; &lt;tr&gt; &lt;td&gt;A1&lt;/td&gt; &lt;td&gt;B1&lt;/td&gt; &lt;td&gt;C1&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;C2&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;C3&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;B2&lt;/td&gt; &lt;td&gt;C3&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;C4&lt;/td&gt; &lt;/tr&gt; </code></pre> <p></p> <p>A and B appear only if they are new (not repeating in every row);</p> <p>I'm trying to use position()</p> <pre><code>&lt;xsl:template match="c"&gt; &lt;tr&gt; &lt;td&gt; &lt;xsl:if test="IT IS THE FIRST C IN A"&gt; &lt;xsl:value-of select="ancestor::A"/&gt; &lt;/xsl:if&gt; &lt;/td&gt; &lt;td&gt; &lt;xsl:if test="position(1)"&gt; &lt;xsl:value-of select="parent"/&gt; &lt;/xsl:if&gt; &lt;/td&gt; &lt;td&gt; &lt;xsl:value-of select="."/&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/xsl:template&gt; </code></pre> <p>It seems that we should emulate position() for ancestor. Is there a general solution for any number of nested rows?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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