fragile Posted July 9, 2010 Share Posted July 9, 2010 Hi,I'm extremely new at this, so please bear with me. I work for an organization and our system uses xsl.One path through our system sets up accounts for people. They must answer some questions and then at the end they get their answers displayed for them in a summary before they do the final submission of the application. With most controls, just the answer the person selected is shown at the end, but with radio buttons it was set up differently.The applicant ends up seeing all of the possible answers and the only way they know which one they chose is by an 'X' next to it.We want to change this behavior and only show the answer they chose.The radio buttons and their respective label are laid out like this for example: <radio name="primaryIncomeSource" value="INDC" /> <label for="primaryIncomeSource" value="INDC"> I am self-employed as an independent contractor performing services for others </label>So thats how the two are related, by the "for" property.In the xsl file, each type of control is handled on its own, for example the radio button section starts out:<xsl:template match="template:radio">and the Label section is similar.So I guess I am asking is there a way to not have the Label text get rendered when its corresponding radio button was not selected?Within the radio section, I can easily do something when its selected value is "false", but the problem seems to be at that point I am into the radio section and how can I possible affect the text of its label when its label is rendered from the Label section?I didn't know how much specific code from my system to post. I was thinking maybe if someone has an idea, they could post some generic examples and I could adjust them for my system but I can certainly post more detailed code of mine if that would help and/or I post more details of this whole situation if need be.thank you!!!! Link to comment Share on other sites More sharing options...
Martin Honnen Posted July 9, 2010 Share Posted July 9, 2010 Consider to post a sample of XML input you want to process and the corresponding result sample you want to create with XSLT. And if you have code you want to adapt then we need to see the relevant code. Link to comment Share on other sites More sharing options...
fragile Posted July 9, 2010 Author Share Posted July 9, 2010 thank you, I will add some more.Here is an xml snippet:<tr row-style="repeat"> <td colspan="2"></td> <td colspan="2"> <radio name="primaryIncomeSource" value="INDC" /> <label for="primaryIncomeSource" value="INDC"> I am self-employed as an <assistive-content href="/Dua_IndependentContractor.htm"> independent contractor </assistive-content> performing services for others </label> </td> </tr> <tr row-style="repeat"> <td colspan="2"></td> <td colspan="2"> <radio name="primaryIncomeSource" value="SELF" /> <label for="primaryIncomeSource" value="SELF"> I am <assistive-content href="/Dua_SelfEmployed.htm"> self-employed </assistive-content> as a sole proprietor, partner or corporate officer (not in farming) </label> </td> </tr> <tr row-style="repeat"> <td colspan="2"></td> <td colspan="2"> <radio name="primaryIncomeSource" value="FRMR" /> <label for="primaryIncomeSource" value="FRMR"> I am a self-employed as a farmer </label> </td> </tr>You can see it is 3 radio buttons, each with their own Label. After the person has answered this question and all the others, their answers will be displayed back and right now they will see all 3 of the radio button Label text contents and a small "X" gets rendered next to the one they selected. So if they chose the first one it would look like this: X I am self-employed as an independent contractor performing services for others I am self-employed as a sole proprietor, partner or corporate officer (not in farming) I am a self-employed as a farmerhope that makes sense.Now here is the stylesheet stuff. Starting with the radio button:<!-- ***** <radio> --> <xsl:template match="template:radio"> <xsl:variable name="name" select="@name" /> <xsl:variable name="value" select="uitip:getValue($name)"/> <xsl:variable name="radio-value" select="@value" /> <xsl:variable name="selected"> <xsl:choose> <xsl:when test="$radio-value = $value">true</xsl:when> <xsl:otherwise>false</xsl:otherwise> </xsl:choose></xsl:variable> <xsl:choose> <xsl:when test="uitip:isEditable($name)"> <xsl:variable name="form-name" select="uitip:getFormName($name)"/> <xsl:variable name="form-id-name"><xsl:value-of select="$name"/>.<xsl:value-of select="$radio-value"/></xsl:variable> <xsl:variable name="form-id" select="uitip:getFormId($form-id-name)"/> <input name="{$form-name}" id="{$form-id}" tabindex="{uitip:tabindex(@tabindex)}" type="radio" value="{$radio-value}"> <xsl:if test="$selected = 'true'"> <xsl:attribute name="checked">checked</xsl:attribute> </xsl:if> </input> <!-- <xsl:if test="@label"> <xsl:value-of select="$name"/>.<xsl:value-of select="$value1"/> </xsl:if> --> <xsl:call-template name="errorIndicator"><xsl:with-param name="name" select="$name" /></xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:if test="$selected = 'true'"> <xsl:if test="$selected = 'true'">X</xsl:if> </xsl:otherwise> </xsl:choose> </xsl:template>Now the Label:<!-- ***** <label> --> <xsl:template match="template:label"> <xsl:variable name="for"><xsl:choose> <xsl:when test="@value"><xsl:value-of select="@for"/>.<xsl:value-of select="@value"/></xsl:when> <xsl:otherwise><xsl:value-of select="@for"/></xsl:otherwise> </xsl:choose></xsl:variable> <xsl:choose> <!-- TODO There is a problem with labels to items in an iterate, this check avoids them. --> <xsl:when test="uitip:isProperty(@for)"> <xsl:variable name="parts" select="uitip:getPropertyParts(@for)"/> <xsl:call-template name="renderLabels"> <xsl:with-param name="for" select="$for" /> <xsl:with-param name="part" select="$parts" /> <xsl:with-param name="parts" select="$parts" /> </xsl:call-template> </xsl:when> <xsl:otherwise><xsl:apply-templates/></xsl:otherwise> </xsl:choose> </xsl:template>that calls this other template:<!-- Render Labels --> <xsl:template name="renderLabels"> <xsl:param name="for" /> <xsl:param name="part" /> <xsl:param name="parts" /> <xsl:choose> <xsl:when test="$part = 1"> <xsl:choose> <xsl:when test="$parts > 1"> <xsl:variable name="for-id" select="uitip:getFormId1($for)"/> <label for="{$for-id}"> <xsl:apply-templates/> </label> </xsl:when> <xsl:otherwise> <xsl:variable name="for-id" select="uitip:getFormId($for)"/> <label for="{$for-id}"> <xsl:apply-templates/> </label> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:when test="$part = 2"> <xsl:variable name="for-id" select="uitip:getFormId2($for)"/> <label for="{$for-id}"> <xsl:call-template name="renderLabels"> <xsl:with-param name="for" select="$for" /> <xsl:with-param name="part" select="$part - 1" /> <xsl:with-param name="parts" select="$parts" /> </xsl:call-template> </label> </xsl:when> <xsl:when test="$part = 3"> <xsl:variable name="for-id" select="uitip:getFormId3($for)"/> <label for="{$for-id}"> <xsl:call-template name="renderLabels"> <xsl:with-param name="for" select="$for" /> <xsl:with-param name="part" select="$part - 1" /> <xsl:with-param name="parts" select="$parts" /> </xsl:call-template> </label> </xsl:when> <xsl:otherwise><xsl:message terminate="yes">Unexpected label part <$part>!</xsl:message></xsl:otherwise> </xsl:choose> </xsl:template>So again how can I prevent the displaying of the Label text for radio buttons that are not "selected" ?It seems like I would have to make a decision about that while I am inside the Radio section but then how can I affect its corresponding Label when that is handled in the Label section?thank you again!! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.