xsl-list
[Top] [All Lists]

[xsl] template matching problem # 18,012

2007-08-23 13:05:44
Hello there,

I created a template to auto-generate html select dropdown boxes based
on some nodes. I can't get it to work precisely how I want it to.

Ideally, I'd like to:

<xsl:apply-templates mode="select"
select="document('XML.xml')/activity/option" />

and have each option become an <option> in my select dropdown.
However, as it is, instead of getting a dropdown box with 3 options
(A, B, C below) I get 3 dropdownboxes.

on the mode="select" template I tried to match both "*", "node()",
".", but these are off.

Have I explained myself well enough?

Thanks,

-Steve

XML===
Activities/XML.xml

<activity>
   <option>A</option>
   <option>B</option>
   <option>C</option>
</activity>
XSL====

       <xsl:template match="/">
                <xsl:apply-templates mode="select"
select="document('../../Activities/XML.xml')/activity/option">
                        <xsl:with-param name="id" select="'program'" />
                </xsl:apply-templates>
       </xsl:template>
        <xsl:template mode="select" match="?????????">
                <xsl:param name="selected" />
                <xsl:param name="id" />
                <xsl:param name="other" />
                <xsl:param name="required" />
                <xsl:param name="otherText">Other</xsl:param>
                <xsl:choose>
                        <xsl:when test="$id=''">
                                ERROR: No id given
                        </xsl:when>
                        <xsl:otherwise>
                                <select id="{$id}" name="{$id}">
                                        <xsl:if test="$required='required'">
                                                <xsl:attribute 
name="required">required</xsl:attribute>
                                        </xsl:if>
                                        <xsl:attribute name="onChange">
                                                if(this.value=='i_Other'){
                                                        new 
Insertion.Before(this,"&lt;input type='text'
id='<xsl:value-of select="$id" />' name='<xsl:value-of select="$id"
/>' /&gt;");Element.remove(this);
                                                }
                                        </xsl:attribute>
                                        <option>Select one</option>
                                        <xsl:for-each select="../node()">
                                                <option>
                                                        <xsl:if 
test=".=$selected">
                                                                <xsl:attribute 
name="selected">selected</xsl:attribute>
                                                        </xsl:if>
                                                        <xsl:attribute 
name="value">
                                                                <xsl:choose>
                                                                        
<xsl:when test="@key"><xsl:value-of select="@key" /></xsl:when>
                                                                        
<xsl:otherwise><xsl:value-of select="." /></xsl:otherwise>
                                                                </xsl:choose>
                                                        </xsl:attribute>
                                                        <xsl:value-of 
select="." />
                                                </option>
                                        </xsl:for-each>
                                        <xsl:if test="$other!=''">
                                                <option 
value="i_Other"><xsl:value-of select="$otherText" /></option>
                                        </xsl:if>
                                </select>
                        </xsl:otherwise>
                </xsl:choose>
        </xsl:template>

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--