Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I select the first element of a node with XSL?
    primarykey
    data
    text
    <p>I'm coding my first website using XML+XSL. The xml I am transforming have this section:</p> <pre><code>&lt;page&gt; &lt;news&gt; &lt;highlights&gt; &lt;entry&gt; &lt;mini&gt;x_thumb.jpg&lt;/mini&gt; &lt;title&gt;title&lt;/title&gt; &lt;text&gt;text&lt;/text&gt; &lt;image&gt;x.jpg&lt;/image&gt; &lt;link&gt;x.html&lt;/link&gt; &lt;/entry&gt; &lt;entry&gt; &lt;mini&gt;z_thumb.jpg&lt;/mini&gt; &lt;title&gt;title&lt;/title&gt; &lt;text&gt;text&lt;/text&gt; &lt;image&gt;z.jpg&lt;/image&gt; &lt;link&gt;z.html&lt;/link&gt; &lt;/entry&gt; &lt;entry&gt; &lt;mini&gt;y_thumb.jpg&lt;/mini&gt; &lt;title&gt;title&lt;/title&gt; &lt;text&gt;text&lt;/text&gt; &lt;image&gt;y.jpg&lt;/image&gt; &lt;link&gt;y.html&lt;/link&gt; &lt;/entry&gt; &lt;/highlights&gt; &lt;/news&gt; &lt;/page&gt; </code></pre> <p>In my .xsl file I want to select the first entry because I'm doing a jQuery image rotator and I need the "default" image to show it. So I coded:</p> <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:template match="/"&gt; [...] &lt;xsl:template match="page/news/highlights/entry[1]"&gt; &lt;div class="main_image"&gt; &lt;img&gt; &lt;xsl:attribute name="src"&gt; &lt;xsl:value-of select="image" /&gt; &lt;/xsl:attribute&gt; &lt;xsl:attribute name="alt"&gt; &lt;xsl:value-of select="title" /&gt; &lt;/xsl:attribute&gt; &lt;/img&gt; &lt;div class="desc"&gt; &lt;div class="block"&gt; &lt;p&gt; &lt;xsl:value-of select="text" /&gt; &lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/xsl:template&gt; [...] </code></pre> <p>And I can't get it working. I've tried various ways, like:</p> <pre><code>&lt;xsl:value-of select="page/news/highlights/entry[1]/image" /&gt; </code></pre> <p>An no way... How can I do it?</p> <p>Thanks in advance!</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.
    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