Subject: RE: [xsl] template matching problem # 18,012 From: cknell@xxxxxxxxxx Date: Thu, 23 Aug 2007 16:49:35 -0400 |
Your template seems to bear little resemblance to your stated desired output. You're leaving out a lot of explanation, aren't you? If what you want is an option list control based on the example XML, then this will do it. Please explain what is missing. ======================== <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:strip-space elements="*" /> <xsl:output method="xml" indent="yes" encoding="UTF-8" /> <xsl:template match="/"> <xsl:apply-templates /> </xsl:template> <xsl:template match="activity"> <OPTGROUP> <xsl:apply-templates /> </OPTGROUP> </xsl:template> <xsl:template match="option"> <OPTION><xsl:value-of select="."/></OPTION> </xsl:template> </xsl:stylesheet> -- Charles Knell cknell@xxxxxxxxxx - email -----Original Message----- From: Steve <subsume@xxxxxxxxx> Sent: Thu, 23 Aug 2007 16:05:07 -0400 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] template matching problem # 18,012 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,"<input type='text' id='<xsl:value-of select="$id" />' name='<xsl:value-of select="$id" />' />");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>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] template matching problem # 1, Steve | Thread | Re: [xsl] template matching problem, Steve |
[xsl] template matching problem # 1, Steve | Date | Re: [xsl] template matching problem, Steve |
Month |