Reputation: 9
need your help with the following... how transform this:
<ul>
<li value="xxx">Text XXX</li>
<li value="zzz">Text ZZZ</li>
<li value="yyy">Text YYY</li>
</ul>
to this
<select>
<option value="xxx">Text XXX</option>
<option value="zzz">Text ZZZ</option>
<option value="yyy">Text YYY</option>
</select>
Thank you in advance.
I tried something that is very far from being correct
<xsl:for-each select="ul/li">
<option value="*/@value">
<xsl:copy-of select="li"/>
</option>
</xsl:for-each>
Upvotes: 0
Views: 30
Reputation: 65156
I wouldn't call your attempt "total crap", it's actually pretty close. What you need to change is:
{}
around values if you want to interpolate them into arguments@value
, no */
value-of
and .
to refer to the current element.Like this:
<select>
<xsl:for-each select="ul/li">
<option value="{@value}">
<xsl:value-of select="." />
</option>
</xsl:for-each>
</select>
Upvotes: 0
Reputation: 167696
It is straight-forward with templates:
<xsl:template match="ul">
<select>
<xsl:apply-templates/>
</select>
</xsl:template>
<xsl:template match="li">
<option value="{@value}">
<xsl:apply-templates/>
</option>
</xsl:template>
Upvotes: 1