RE: [xsl] xsl:if / variables / fancy / confusing

Subject: RE: [xsl] xsl:if / variables / fancy / confusing
From: "Johnathon Wright" <jw@xxxxxxxxxxxxx>
Date: Fri, 18 Nov 2005 09:39:19 -0600
Thanks! I was able to get everything to work properly. I ended up changing the XML for errors, but I had to use XML similar to that to populate the drop-downs that had already been selected.

If someone finds this in the archive, watch out for what I did with populating against previous submissions... I know that option_ids will not be duplicated for different attribute_ids. If that weren't the case, I would have had to replace the * with something else.

<xsl:for-each select="attribute">
<select name="attribute_{attribute_id}">
<xsl:if test="/configuration/details/errors/error/name = concat('attribute_', attribute_id)">
<xsl:attribute name="style">background-color:#FFCC00; color:red; font-weight:bolder;</xsl:attribute>
</xsl:if>


<option value="">Select a <xsl:value-of select="attribute_name" /> </option>
<xsl:for-each select="option">


<option value="{option_id}">
<xsl:if test="/configuration/request/* = option_id">
<xsl:attribute name="selected">TRUE</xsl:attribute>
</xsl:if>
<xsl:value-of select="option_name"/><xsl:if test="price_offset &gt; 0"> - add <xsl:value-of select="format-number(price_offset, '$###,###,.00')" /></xsl:if></option>



</xsl:for-each> </select> </xsl:for-each>



Hi Johnathon,

You cannot use attribute value templates within attributes that are expected to contain XPath
expressions themselves. Not a very nice solution, but you could use:


<xsl:if test="/configuration/details/errors/*[local-name() = concat('attribute_', attribute_id)]">
<xsl:attribute name="style">xyz</xsl:attribute>
</xsl:if>


Regards,
Geert



------------------------------

Date: Thu, 17 Nov 2005 22:37:44 -0000
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Subject: RE: [xsl] xsl:if / variables / fancy / confusing

Don't try to pack meaning and structure into element names. Instead of
<attribute_285>, use <attribute id="285">. It's much easier to manipulate.

Michael Kay
http://www.saxonica.com/

Current Thread