I'm trying to add the attribute 'selected' to <option>
. I've tried various ways and I can't get it working. This is how I'm trying it:
<xsl:for-each select="page/index/values/albums">
<option>
<xsl:attribute name="value"><xsl:value-of select="id" /></xsl:attribute>
<xsl:if test="page/index/values/album = id">
<xsl:attribute name="selected">selected</xsl:attribute>
</xsl:if>
<xsl:value-of select="name" />
</option>
</xsl:for-each>
What is the correct form for the <xsl:if />
?
Edit:
My XML file:
<page>
<index>
<values>
<album>2</album>
<albums>
<id>1</id>
<name>Album #1</name>
</albums>
<albums>
<id>2</id>
<name>Album #2</name>
</albums>
</values>
</index>
</page>
Output:
<option value="1">Album #1</option>
<option value="2" selected="selected">Album #2</option>