Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are missing the idea of a <em>context node</em>. Within a <code>xsl:for-each</code>, everything you refer to is about or relative to the selected nodes. So, for instance, within <code>&lt;xsl:for-each select="News/Sport"&gt;</code>, the context node is the <code>Sport</code> elements, and a test like <code>&lt;xsl:if test="local-name()='Basketball'"&gt;</code> is always going to be <em>false</em> because the local name is always <code>Sport</code>.</p> <p>It looks like you want just <code>&lt;xsl:if test="Basketball"&gt;</code> which tests whether there are any <code>Basketball</code> child nodes of the current <code>Sport</code> node.</p> <p>The same thing applies to <code>&lt;xsl:value-of select="News/Sport/Basketball/Phrases/Phrase"/&gt;</code>. Because everything is relative to the <code>Sport</code> node, XSLT is looking for <code>News/Sport/Basketball/Phrases/Phrase</code> <em>within the <code>Sport</code> element</em>, which never exists.</p> <p>In addition, you can just put text in literally: there is no need for an <code>xsl:text</code> element here, so your code should look like</p> <pre><code>&lt;xsl:for-each select="News/Sport"&gt; &lt;xsl:if test="Basketball"&gt; &lt;p&gt;Basketball Sport&lt;/p&gt; &lt;xsl:value-of select="Basketball/Phrases/Phrase"/&gt; &lt;/xsl:if&gt; &lt;/xsl:for-each&gt; </code></pre> <p>You can refine this further by adding a <em>predicate</em> to the <code>for-each</code> selection, so that it matches only <code>Sport</code> elements with a <code>Basketball</code> child. Like this</p> <pre><code>&lt;xsl:for-each select="News/Sport[Basketball]"&gt; &lt;p&gt;Basketball Sport&lt;/p&gt; &lt;xsl:value-of select="Basketball/Phrases/Phrase"/&gt; &lt;/xsl:for-each&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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