Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your code seems to be okay, but the same thing can be expressed simpler.</p> <pre><code>&lt;xsl:for-each select="//book[price &amp;lt; 30]"&gt; &lt;xsl:if test="title[@category='fiction']"&gt; &lt;span style="color:blue;font-weight:bold"&gt;&lt;xsl:value-of select="title"/&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="color:red;font-style:italic"&gt;&lt;xsl:value-of select="author[1]" /&gt;&lt;/span&gt; &lt;xsl:if test="author[2]"&gt; &lt;span style="color:red;font-style:italic"&gt; et al&lt;/span&gt; &lt;/xsl:if&gt; &lt;br /&gt; &lt;span&gt;&lt;xsl:value-of select="price"/&gt;&lt;/span&gt;&lt;br /&gt; &lt;/xsl:if&gt; &lt;/xsl:for-each&gt; </code></pre> <p>The above is shorter than your code, but it's not very elegant. This is better.</p> <pre><code>&lt;xsl:template match="/"&gt; &lt;xsl:apply-templates select="//book[price &amp;lt; 30 and @category='fiction']" /&gt; &lt;/xsl:template&gt; &lt;xsl:template match="book"&gt; &lt;div class="book"&gt; &lt;div class="title"&gt;&lt;xsl:value-of select="title"/&gt;&lt;/div&gt; &lt;div class="author"&gt; &lt;xsl:value-of select="author[1]" /&gt;&lt;xsl:if test="author[2]"&gt; et al&lt;/xsl:if&gt; &lt;/div&gt; &lt;div class="price"&gt;&lt;xsl:value-of select="price"/&gt;&lt;/div&gt; &lt;/div&gt; &lt;/xsl:template&gt; </code></pre> <ul> <li>Write generic templates that can display every book, like this one.</li> <li>Use them via <code>&lt;xsl:apply-templates&gt;</code> instead of repeating yourself with <code>&lt;xsl:for-each&gt;</code>.</li> <li>Use CSS to style the output. Inline styles are ugly.</li> </ul>
 

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