Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make XSLT xsl:if work
    primarykey
    data
    text
    <p>I am trying to make this (xml 1.0) code work . I am new to this and already exhausted myself in trying different ways. Does someone know my mistake?</p> <pre><code>&lt;xsl:for-each select="News/Sport"&gt; &lt;xsl:if test="local-name()='Basketball'"&gt; &lt;p&gt; &lt;xsl:text&gt;Basketball Sport&lt;/xsl:text&gt; &lt;/p&gt; &lt;xsl:value-of select="News/Sport/Basketball/Phrases/Phrase"/&gt; &lt;/xsl:if&gt; &lt;/xsl:for-each&gt; </code></pre> <p>When I transform it into an HTML file the content doesn't show up. When I remove the <code>xsl:for each</code> and the <code>xsl:if statements</code> the content is successfully presented. I only wish that the content is first checked (if it is available in the XML file) and if yes, that it is taken from the XML content.</p> <p>Thank you in advance for your help!</p> <p>EDIT:</p> <p>This is my XML code</p> <pre><code>&lt;News&gt; &lt;Sport&gt; &lt;Basketball&gt; &lt;Phrases&gt; &lt;Phrase&gt;Zach Randolph recovered the opening tipoff in Game 1 of the Western Conference Finals, and he didn’t touch the ball again until the possession following the Grizzlies’ first timeout. &lt;/Phrase&gt; &lt;Phrases&gt; &lt;/Basketball&gt; &lt;/Sport&gt; &lt;/News&gt; </code></pre> <p><strong>EDIT2:</strong></p> <p>Could you tell me why I cannot apply a template inside this below function? Only the text works now:(</p> <pre><code>&lt;xsl:for-each select="News/Sport[Basketball]"&gt; &lt;xsl:apply-templates select="News/Sport/*" /&gt; &lt;/xsl:for-each&gt; &lt;xsl:template match="Basketball"&gt; &lt;p&gt; &lt;xsl:text&gt;Basketball Sport&lt;/xsl:text&gt; &lt;/p&gt; &lt;xsl:apply-templates select="Phrases/Phrase"/&gt; &lt;/xsl:template&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.
 

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