Jump to content

Radio Buttons


theredking
 Share

Recommended Posts

Hello, i am writing an xslt to transform and display my quiz xml document. The questions are displayed and answers are displayed with radio buttons next to them. But i don't know to to provide them values or group them question by questions as all the radio buttons seem to be linked becasue when one is clicked it turns off another one from another question. I have tried amending this problem but with little success, any help would be much apprechiated. Thank you. my code is below.

<?xml version="1.0"?><xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0" > <xsl:template match ="/">  <html>    <body>	<form name="myform" action="http://www.manut.com" method="POST">      <center>        <h2> <xsl:value-of select="XMultipleChoice/QuizName" /> </h2>      </center>      <hr>  </hr>      <!-- create the links -->      <ul>        <xsl:for-each select="XMultipleChoice/Units/Unit">          <li>            <a>              <xsl:attribute name="href">                <xsl:text>#Unit-</xsl:text>                <xsl:value-of select="Question" />              </xsl:attribute>              <xsl:value-of select="Question" />            </a>          </li>        </xsl:for-each>      </ul>      <!-- now the actual slides -->      <xsl:for-each select="XMultipleChoice/Units/Unit">        <hr> </hr>                  <h3>            <a>                          <xsl:attribute name="name">                <xsl:text>#Unit-</xsl:text>                <xsl:value-of select="QuestionNo" />              </xsl:attribute>              <xsl:value-of select="QuestionNo" />              -               <xsl:attribute name="name">                <xsl:text>#Unit-</xsl:text>                <xsl:value-of select="Subject" />              </xsl:attribute>              <xsl:value-of select="Subject" />                          </a>          </h3>                  <li>          <h3>            <a>              <xsl:attribute name="name">                <xsl:text>#Unit-</xsl:text>                <xsl:value-of select="Question" />              </xsl:attribute>              <xsl:value-of select="Question" />            </a>          </h3>        </li>        <ul>         [B] <xsl:for-each select="Answer" >            <p align = "left"><input type = "radio" name = "name1" value = ""/><xsl:value-of select="." /></p>          </xsl:for-each>[/B]        </ul>      </xsl:for-each>     </form>    </body>  </html> </xsl:template> </xsl:stylesheet>

Link to comment
Share on other sites

Would you provide a sample XML file, so I could test what you have up to now? I mean... it all looks good at first sight, excluding the fact that you have two "name" attributes in a single anchor, which however shouldn't be the cause of this.What if you place each group (question with it's answers) in a <fieldset> element maybe?

Link to comment
Share on other sites

Would you provide a sample XML file, so I could test what you have up to now? I mean... it all looks good at first sight, excluding the fact that you have two "name" attributes in a single anchor, which however shouldn't be the cause of this.What if you place each group (question with it's answers) in a <fieldset> element maybe?

Here is the XML file. Thanks for this!
<?xml version="1.0" ?><?xml-stylesheet type="text/xsl" href="quizdisplaypd.xsl"?><!--  <!DOCTYPE XMultipleChoice SYSTEM "quizpd.dtd">   -->  <XMultipleChoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="quizschemapd.xsd"> 	<QuizName>Parmjeet Dayal Great XML Assignment Quiz</QuizName>	<Units>  <Unit> 	 <QuestionNo>1</QuestionNo> 	 <Subject>Dave Chappelle Show</Subject> 	 <Question>Who is Rick James?</Question> 	 <Answer Corr="Y">Rick James</Answer> 	 <Answer>Charlie Murphy</Answer> 	 <Answer>Dave Chappelle</Answer> 	 <Answer>Eddie Murphy</Answer>  </Unit>  <Unit> 	 <QuestionNo>2</QuestionNo> 	 <Subject>Dave Chappelle Show</Subject> 	 <Question>Should you put feet on other peoples couches?</Question> 	 <Answer>Yes</Answer> 	 <Answer>No</Answer> 	 <Answer>In someone else's house</Answer> 	 <Answer Corr="Y">In Eddie Murphy's house, he can afford it</Answer>  </Unit>  <Unit> 	 <QuestionNo>3</QuestionNo> 	 <Subject>Wrestling</Subject> 	 <Question>Who is the greatest wrestler of all time?</Question> 	 <Answer>Hulk Hogan</Answer> 	 <Answer>The Rock</Answer> 	 <Answer Corr="Y">Goldberg</Answer> 	 <Answer>Stone Cold Steve Austin</Answer>  </Unit>	  <Unit> 	 <QuestionNo>4</QuestionNo> 	 <Subject>Music</Subject> 	 <Question>Who is the lead singer of The Stone Roses is?</Question> 	 <Answer>Noel Gallagher</Answer> 	 <Answer Corr="Y">Ian Brown</Answer> 	 <Answer>Chris Martin</Answer> 	 <Answer>Snoop Dog</Answer>  </Unit>		</Units></XMultipleChoice>

Link to comment
Share on other sites

I used the generate-id() function at both the questions and answers to create links between them. In order to group the questions' answers, I had to place a name for each group of questions. Using the QuestionNo for each answer seemed as the most appropriate idea :) .

<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" ><xsl:template match="/"> <html>   <body><form name="myform" action="http://www.manut.com" method="POST">     <center>       <h2> <xsl:value-of select="XMultipleChoice/QuizName" /> </h2>     </center>     <hr />     <!-- create the links -->       <ul>       <xsl:for-each select="XMultipleChoice/Units/Unit">         <li>           <a href="#{generate-id(Question)}">             <xsl:value-of select="Question" />           </a>         </li>       </xsl:for-each>     </ul>     <!-- now the actual slides -->     <xsl:for-each select="XMultipleChoice/Units/Unit">       <hr />                <h3>           <a>                        <xsl:attribute name="name">               <xsl:text>#Unit-</xsl:text>               <xsl:value-of select="QuestionNo" />             </xsl:attribute>             <xsl:value-of select="QuestionNo" />             -             <xsl:attribute name="name">               <xsl:text>#Unit-</xsl:text>               <xsl:value-of select="Subject" />             </xsl:attribute>             <xsl:value-of select="Subject" />                        </a>         </h3>                <li>         <h3 id="{generate-id(Question)}">             <xsl:value-of select="Question" />         </h3>       </li>       <ul>    <xsl:for-each select="Answer" >  <label for="{generate-id(current())}">  <p align = "left">  <input type="radio" id="{generate-id(current())}" name="{string(../QuestionNo)}" value=""/><xsl:value-of select="." />  </p>  </label>        </xsl:for-each>  </ul>     </xsl:for-each>    </form>   </body> </html></xsl:template></xsl:stylesheet>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...