Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import form value in XSL

Status
Not open for further replies.

explicit

Technical User
Apr 13, 2008
1
BE
Hi,

I'm making a xml file about different groups and there members.

I like to make a choice in a selectlist in an xsl file to get only the members from the group that I select.
The problem is that I can't get the link working between the form and the xsl.

I want to replace 'Animatie' (<xsl:when test="@dnaam = 'Animatie'">), witch is one of the group names, with a variable that changes everytime you select another group with the selectlist in the form that's on top of the xsl file.

The options in the selectlist are 'Animatie', 'Arbeidstrajectbegeleiding', 'Financiele Dienst' and 'Juridische Dienst' (they are dutch groupnames). So when you select one, the variable that has to come behind @dnaam = ........ has to change into the selected option.

XML file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="opmaak.xsl"?>
<diensten>
	<dienst dnaam="Animatie">
			<lid>
				<persnaam>Persoon 1</persnaam>
				<functie>Funtie 1</functie>
				<kort></kort>
				<dect>521</dect>
			</lid>
			<lid>
				<persnaam>Persoon 2</persnaam>
				<functie>Functie 2</functie>
				<kort></kort>
				<dect>501</dect>
			</lid>
			<lid>
				<persnaam>Persoon 3</persnaam>
				<functie></functie>
				<kort></kort>
				<dect>521</dect>
			</lid>
	</dienst>
	<dienst dnaam="Arbeidstrajectbegeleiding">
			<lid>
				<persnaam>Persoon 4</persnaam>
				<functie></functie>
				<kort></kort>
				<dect>517</dect>
			</lid>
			<lid>
				<persnaam>Persoon 5</persnaam>
				<functie></functie>
				<kort></kort>
				<dect>517</dect>
			</lid>
			<lid>
				<persnaam>Persoon 6</persnaam>
				<functie></functie>
				<kort></kort>
				<dect>517</dect>
			</lid>
	</dienst>
	<dienst dnaam="Financiele Dienst">
			<lid>
				<persnaam>Persoon 7</persnaam>
				<functie>Functie 3</functie>
				<kort>326</kort>
				<dect></dect>
			</lid>
			<lid>
				<persnaam>Persoon 8</persnaam>
				<functie></functie>
				<kort>325</kort>
				<dect></dect>
			</lid>
	</dienst>
	<dienst dnaam="Juridische Dienst">
			<lid>
				<persnaam>Persoon 9</persnaam>
				<functie>Functie 4</functie>
				<kort></kort>
				<dect>516</dect>
			</lid>		
	</dienst>
</diensten>

XSL file:
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
<xsl:template match="/">
    <html>
      <head>
        <title>Personeelsleden</title>
		<script language="javascript">
		<![CDATA[
			function jump()
			{
				d = document;
				dienstnaam=d.form1.dienstlijst.options[d.form1.dienstlijst.selectedIndex].value;
				d.form1.waardeveld.value = dienstnaam;
			}
		]]>
		</script>
      </head>
      <body>
		<form name="form1">
		Zoeken op dienst:
		<select name="dienstlijst" onchange="jump()">
    		<option value="Animatie">Animatie</option>
    		<option value="Arbeidstrajectbegeleiding">Arbeidstrajectbegeleiding</option>
    		<option value="Financiele Dienst">Financiele Dienst</option>
    		<option value="Juridische Dienst">Juridische Dienst</option>
		</select>
		<input type="text" name="waardeveld" style="visibility:visible"/>
		</form>
        <h1>Personeelsleden</h1>
        <table>
            <tr>
              <td id="titel">
                Naam:
              </td>
              <td id="titel">
                Functie:
              </td>
              <td id="titel">
                Kort:
              </td>
              <td id="titel">
                Dect:
              </td>
            </tr>
         <xsl:for-each select="diensten/dienst">
         <xsl:choose>
         <xsl:when test="@dnaam = 'Animatie'">
         <xsl:for-each select="lid">
          <tr>
            <td id="tabel2">
              <xsl:value-of select="persnaam"/>
            </td>
            <td id="tabel">
              <xsl:value-of select="functie"/>
            </td>
            <td id="tabel">
              <xsl:value-of select="kort"/>
            </td>
            <td id="tabel">
              <xsl:value-of select="dect"/>
            </td>
          </tr>
          </xsl:for-each>
    	</xsl:when>
        </xsl:choose>
        </xsl:for-each>
        </table>
    </body>
    </html>
</xsl:template>
</xsl:stylesheet>

Thanks,

EJ
 
[1] As it stands, you won't be able to switch the display. You've to put the xml and xslt document to a server and apply some server-side script to make the transformation which is capable to take in parameters.
[2] Modify the client-side jscript function jump() so that it will submit the form. Add the action and method attributes to the form.
[3] It action script will take the request variables (depending on post or get method) and use that info, in particular the form element named "waardeveld" to feed to the xslt as parameters. The action script can be the originating script, that means the page submits to itself.
[4] Define a paramter in the xslt document so that it takes the place of hard-scripted "Animatie".
[5] The server-side script therefore depends on the platform you are working with and cannot be answered without.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top