Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

XML and HTML Forms

   I have a XML document that I am combining with and XSL document to produce an HTML document.  This is creating a form that with the information from the XML document filling out the form, i.e. <Name>Paul</Name> ends up creating a textbox with Paul written in the textbox.
    This part of the document is fine, the problem that I am having is with the Checkboxes section.  I want to have one of the pieces of information displayed as checkboxes or option buttons.  So basically I have <CarBenefits>Auto Program</CarBenefits> and on the page I have two option buttons one that says Auto Program and one that says 29 Cents Per Mile.  I want the Option Button that has the same Value as the what is in the CarBenefits tag to be selected.  
    Here is what I have
<input type="radio" value="Auto Program" name="CarBenefits">Auto Program

<input type="radio" name="CarBenefits" value="Twenty Nine Cents Per Mile">29 Cents Per Mile
0
cavacasp
Asked:
cavacasp
  • 5
  • 4
1 Solution
 
memingCommented:
Try:

<xsl:template match="CarBenefit">
    <xsl:choose>
      <xsl:when test="contains(.,'Auto Program')">
<input type="radio" value="Auto Program" name="CarBenefits" checked>Auto Program
<input type="radio" value="Twenty Nine Cents Per Mile" name="CarBenefits">29 Cents Per Mile
      </xsl:when>
      <xsl:otherwise>      
<input type="radio" value="Auto Program" name="CarBenefits">Auto Program
<input type="radio" value="Twenty Nine Cents Per Mile" name="CarBenefits" checked>29 Cents Per Mile
    </xsl:otherwise>
    </xsl:choose>
</xsl:template>
0
 
cavacaspAuthor Commented:
I am getting the following error

Keyword xsl:template may not be used here.


Because the template keyword can not be used in the middle of the XSL document inside of another XSL document.  I have a document that uses xsl:template to parse the whole document, so I con't use the template tag inside of the other one.  So what can I do to accomplish this.
0
 
memingCommented:
<xsl:template match="whatever">
<!-- ....  -->
   <xsl:apply-templates select="CarBenefit"/>
<!-- ....  -->
</xsl:template>
<!-- previous code goes here -->


This should work. You need to apply the new template inside your existing one.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
cavacaspAuthor Commented:
Now I'm getting the error

Unknown method. -->contains(.<--, 'FullTime')

on this

<xsl:template match="EmploymentStatus">
      <xsl:choose>
            <xsl:when test="contains(., 'FullTime')">
                  <TD Width="31%"><INPUT Type="radio" name="EmploymentStatus" Value="FullTime" Checked="" /><FONT face="times new roman" size="1">Full-Time</FONT></TD>
                  <TD Width="23%"><INPUT Type="radio" name="EmploymentStatus" Value="PartTime" /><FONT face="times new roman" size="1">Part-Time</FONT></TD>
                  <TD Width="21%"><INPUT Type="radio" name="EmploymentStatus" Value="CompanyTemporary" /><FONT face="times new roman" size="1">Company Temporary</FONT></TD>
                  <TD Width="25%"><INPUT Type="radio" name="EmploymentStatus" Value="AgencyTemporray" /><FONT face="times new roman" size="1">Agency Temporary</FONT></TD>
            </xsl:when>
            <xsl:when test="contains(., 'PartTime')">
                  <TD Width="31%"><INPUT Type="radio" name="EmploymentStatus" Value="FullTime" /><FONT face="times new roman" size="1">Full-Time</FONT></TD>
                  <TD Width="23%"><INPUT Type="radio" name="EmploymentStatus" Value="PartTime" Checked="" /><FONT face="times new roman" size="1">Part-Time</FONT></TD>
                  <TD Width="21%"><INPUT Type="radio" name="EmploymentStatus" Value="CompanyTemporary" /><FONT face="times new roman" size="1">Company Temporary</FONT></TD>
                  <TD Width="25%"><INPUT Type="radio" name="EmploymentStatus" Value="AgencyTemporray" /><FONT face="times new roman" size="1">Agency Temporary</FONT></TD>
            </xsl:when>
            <xsl:when test="contains(., 'CompanyTemporary')">
                  <TD Width="31%"><INPUT Type="radio" name="EmploymentStatus" Value="FullTime" /><FONT face="times new roman" size="1">Full-Time</FONT></TD>
                  <TD Width="23%"><INPUT Type="radio" name="EmploymentStatus" Value="PartTime" /><FONT face="times new roman" size="1">Part-Time</FONT></TD>
                  <TD Width="21%"><INPUT Type="radio" name="EmploymentStatus" Value="CompanyTemporary" Checked="" /><FONT face="times new roman" size="1">Company Temporary</FONT></TD>
                  <TD Width="25%"><INPUT Type="radio" name="EmploymentStatus" Value="AgencyTemporray" /><FONT face="times new roman" size="1">Agency Temporary</FONT></TD>
            </xsl:when>
            <xsl:otherwise>
                  <TD Width="31%"><INPUT Type="radio" name="EmploymentStatus" Value="FullTime" /><FONT face="times new roman" size="1">Full-Time</FONT></TD>
                  <TD Width="23%"><INPUT Type="radio" name="EmploymentStatus" Value="PartTime" /><FONT face="times new roman" size="1">Part-Time</FONT></TD>
                  <TD Width="21%"><INPUT Type="radio" name="EmploymentStatus" Value="CompanyTemporary" /><FONT face="times new roman" size="1">Company Temporary</FONT></TD>
                  <TD Width="25%"><INPUT Type="radio" name="EmploymentStatus" Value="AgencyTemporray" Checked="" /><FONT face="times new roman" size="1">Agency Temporary</FONT></TD>
            </xsl:otherwise>
      </xsl:choose>
</xsl:template>



this section of code is after </xsl:template> and the </xsl:stylesheet> tag.  I can include the whole Stylesheet if you need me to, but it is very long about 300 lines.
0
 
memingCommented:
If you are using IE5, it doesn't support the W3C recommended XSLT. You would need to do some Javascript to get it to work then.
0
 
cavacaspAuthor Commented:
Yes I am using IE5 so what do I have to do Anybody?
0
 
cavacaspAuthor Commented:
Adjusted points from 200 to 300
0
 
cavacaspAuthor Commented:
Somebody please help.  Any idea on how to go about doing this.
0
 
memingCommented:
http://msdn.microsoft.com/xml/reference/xsl/Examples.asp

<xsl:template match="CarBenefit[.='Auto Program']">
<input type="radio" value="Auto Program" name="CarBenefits" checked>Auto Program
<input type="radio" value="Twenty Nine Cents Per Mile" name="CarBenefits">29 Cents Per Mile
</xsl:template>

<xsl:template match="CarBenefit[.='Twenty Nine Cents Per Mile']">
<input type="radio" value="Auto Program" name="CarBenefits">Auto Program
<input type="radio" value="Twenty Nine Cents Per Mile" name="CarBenefits" checked>29 Cents Per Mile
</xsl:template>

Try this...
0
 
JagarCommented:
   OK I am not getting the radio buttons, but am getting the rest of the form displayed.  
    In the main part where I have a for-each statement I have this

<tr>
<td width="100%"><FONT face="times new roman" size="1">Why is employee being replaced:</FONT>
<xsl:apply-templates select="ReasonForReplacement"/>
</td>
</tr>

Then outside of that main template part I have this
<xsl:template match="ReasonForReplacement[.='Termination']">
<input type="radio" name="ReasonForReplacement" value="Termination" Checked="" /><FONT face="times new roman" size="1">Termination </FONT>
<input type="checkbox" name="ReasonForReplacement" value="Transfer" /><FONT face="times new roman" size="1">Transfer</FONT>
</xsl:template>
<xsl:template match="ReasonForReplacement[.='Transfer']">
<input type="radio" name="ReasonForReplacement" value="Termination" /><FONT face="times new roman" size="1">Termination</FONT>
<input type="checkbox" name="ReasonForReplacement" value="Transfer" Checked="" /><FONT face="times new roman" size="1">Transfer</FONT>
</xsl:template>


But in the form where the ReasonForReplacement button should be there is nothing.

What am I doing wrong?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now