Note that there are some explanatory texts on larger screens.

plurals
  1. POCompare variable in preceding-sibling with current node
    text
    copied!<p>I have the following template:</p> <pre><code>&lt;xsl:template match="footnote"&gt; &lt;xsl:variable name = "string"&gt; &lt;xsl:value-of select="."/&gt; &lt;/xsl:variable&gt; &lt;xsl:variable name = "bool"&gt; &lt;xsl:if test="$string = preceding-sibling::node()/$string"&gt; &lt;xsl:text&gt;false&lt;/xsl:test&gt; &lt;/xsl:if&gt; &lt;/xsl:variable&gt; &lt;xsl:if test="$bool != 'false'"&gt; &lt;!-- DO STUFF --&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; </code></pre> <p>I'm trying to check the $string variable of the current node and check it against all previous footnote nodes to see if they have the same $string variable. If it doesn't match up with any of the preceding siblings then it should do stuff, otherwise it should do nothing.</p> <p>With the code I have, the test "$string = preceding-sibling::node()/$string" always evaluates to true, even when no footnote nodes have been created yet.</p> <p>Can anyone help me out? I'm having a hard time creating the expression to compare against the variable in all of the previous siblings.</p> <p><strong>EDIT:</strong> Sample XML:</p> <pre><code>&lt;xml&gt; &lt;footnote&gt;Footnote 1&lt;/footnote&gt; &lt;footnote&gt;Footnote 2&lt;/footnote&gt; &lt;footnote&gt;Footnote 1&lt;/footnote&gt; &lt;footnote&gt;Footnote 1&lt;/footnote&gt; &lt;footnore&gt;Footnote 3&lt;/footenote&gt; &lt;/xml&gt; </code></pre> <p>I'm trying to transform that into:</p> <pre><code>&lt;xml&gt; &lt;footnote&gt;Footnote 1&lt;/footnote&gt; &lt;footnote&gt;Footnote 2&lt;/footnote&gt; &lt;footnote&gt;Footnore 3&lt;/footnore&gt; &lt;/xml </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