Annotation of loncom/html/adm/help/tex/BridgeTask_XMLVariable.tex, revision 1.2

1.1       rezaferr    1: \label{BridgeTask_XMLVariable}
                      2: 
                      3: To create difference versions of Bridge Tasks for each student, parts of the questions are defined using variables. Each variable contains multiple instances of possible values and LON-CAPA randomly selects an instance to give to the student. 
                      4: 
                      5: All variables are placed inside a Setup element. Each setup element has an id attribute which contains the name of the variable. The possible instances or values of those variables are placed inside the setup element inside an Instance tag. Each Instance element has two mandatory attributes, the OptionalRequired attribute which should be set to 0, and the unique id of that instance. The value of the id attribute can be any text as long as it is unique throughout the document.
                      6: 
                      7: The actual data of the instance is placed inside InstanceText tags. Currently the instance data is created with a loncapa/perl script. In this script the parameters of the variable are set. The syntax to set the parameter of a variable is '\$variableName \{fieldname\} = "fieldValues"'. The variable name is taken from the attribute id from the Setup element, the field name is the name of the parameter the author sets, and the fieldValue is simply the value of the field. The first parameter that must be set is the instance field, with the value being an identifier of the instance.
                      8: 
                      9: The example below shows a portion of the bridge task XML file. This portion should be placed inside the task element :Lines between $<!--$ and $-->$ or $/*$ and $*/$ are comments and should not be typed into the editor. 
                     10: 
                     11: \begin{verbatim}
                     12: <!-- Create a variable named entity Subject  -->
                     13: <Setup id="entitySubject">
                     14: 
                     15: <!-- The first instance. With id instanceHarry -->
                     16: <Instance OptionalRequired="0" id="instanceHarry">
                     17: 
                     18: <!-- The parameters for this instance -->
                     19: <InstanceText>
                     20: 	<script type='loncapa/perl'>
1.2     ! rezaferr   21: 		/* The first line must be the instance id */
        !            22: 		$entitySubject{instance} = "instanceHarry";
        !            23: 		/* The two parameters. Personname = Harry and place=zoo */	
        !            24: 		$entitySubject{personname} = "Harry";	
        !            25: 		$entitySubject{place} = "zoo";	
1.1       rezaferr   26: 	</script>
                     27: 
                     28: </InstanceText>
                     29: </Instance>
                     30: <!--End of instanceHarry-->
                     31: 
                     32: <!-- The second instance. With id instanceBetty -->
                     33: <Instance OptionalRequired="0" id="instanceBetty">
                     34: 
                     35: <!-- The parameters for this instance -->
                     36: <InstanceText>
                     37: 	<script type='loncapa/perl'>
1.2     ! rezaferr   38: 		/* The first line must be the instance id */
        !            39: 		$entitySubject{instance} = "instanceBetty";	
        !            40: 		/* The two parameters. Personname = Betty and place=park */	$entitySubject{personname} = "Betty";	
        !            41: 		$entitySubject{place} = "park";	
1.1       rezaferr   42: 	</script>
                     43: </InstanceText>
                     44: </Instance>
                     45: <!--End of instanceBetty-->
                     46: 
                     47: </Setup>
                     48: \end{verbatim}
                     49: 
                     50: The example above describes a variable question. It has two different possible values for the entity "subject", Harry and zoo or Betty and park. Variables can be placed inside the questions by using the variable name and field name. 
                     51: The first line $<$Setup id="entitySubject"$>$ creates a variable named entitySubject (based on the id attribute of this line).
                     52: 
                     53: The first instance of this variable is shown from lines 2 to 10. Line two $<$Instance OptionalRequired="0" id="instanceHarry"$>$ marks the beginning of the instance element named instanceHarry (based on the id attribute). The OptionalRequired is given a value of 0. Lines 3-9 determine the actual value of this variable. Lines 3 and 4 must be typed as shown. Lines 5-7 define the instance properties, which must be of the form \$ $<$variable\_name$>$ \{$<$property\_name$>$ \} = $<$value$>$. The first line of the property must be the instance property (see line 5 of example), with the value being the id of the instance. Other lines (6-7) can be used for any attributes you wish to define. The closing $<$/script$>$, $<$/InstanceText$>$ and $<$/Instance$>$ tags must be typed as shown.
                     54: 
                     55: Line 12-21 shows the second instance with the same rules as the first instance. Line 23 $<$/Setup$>$ gives the closing Setup tag which must be as shown..
1.2     ! rezaferr   56: The example of the usage of this variable inside the question is this text: 
        !            57: 
1.1       rezaferr   58: This is a test question. \$entitySubject\{personname\}
                     59:  went to the \$entitySubject\{place\}. .
                     60:  
                     61: The LON-CAPA engine will replace any instance of \$$<$variable\_name$>$ ($<$property\_name$>$) with the correct value, depending on the randomly chosen instance. 
                     62: 
                     63: Based on this code, two different questions are possible:
                     64: \begin{enumerate}
                     65: \item This is a test question. Harry went to the zoo
                     66: \item This is a test question. Betty went to the park
                     67: \end{enumerate}
                     68: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>