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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

selecting which entry to display from XML file

Status
Not open for further replies.

birney29

Programmer
Oct 11, 2001
140
GB
Hi, me again!

ive got an xsl page that takes values from an xml document describing a person and prints them out on screen. what i would like is to press a button and the values/data of the next person in the xml file would be displaye. and also a button to go back the way. the xml is as follows:
Code:
<?xml version=&quot;1.0&quot;?>
<!-- created by Kenny -->
<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;person.xsl&quot;?>
<details xmlns:xsi=&quot;[URL unfurl="true"]http://www.w3.org/2000/10/XMLSchema-instance&quot;>[/URL]
<person>
	<Address>36 Hillpark Avenue Paisley</Address>
	<Title>Mr</Title>
	<CertNum>F12345</CertNum>
	<FirstName>Kenneth</FirstName>
	<Gender>Male</Gender>
	<LastName>Birney</LastName>
	<OtherLastName>none</OtherLastName>
	<PreferedName>Kenny</PreferedName>
	<Nationality>Scottish</Nationality>
	<SCRONumber>123456</SCRONumber>
	<Roles>Star</Roles>
	<OtherFirstName>God</OtherFirstName>
	<DateOfBirth>22/10/1981</DateOfBirth>
	<OccupationCode>1</OccupationCode>
	<DriverNumber>5</DriverNumber>
</person>
<Person>
<Address>36 Hillpark Avenue Paisley</Address>
	<Title>Dr</Title>
	<CertNum>F12345</CertNum>
	<FirstName>Nick</FirstName>
	<Gender>Male</Gender>
	<LastName>rivera</LastName>
	<OtherLastName>none</OtherLastName>
	<PreferedName>Kenny</PreferedName>
	<Nationality>Scottish</Nationality>
	<SCRONumber>123456</SCRONumber>
	<Roles>Star</Roles>
	<OtherFirstName>God</OtherFirstName>
	<DateOfBirth>22/10/1981</DateOfBirth>
	<OccupationCode>1</OccupationCode>
	<DriverNumber>5</DriverNumber>
</person>
</details>


the xsl is :


<?xml version=&quot;1.0&quot;?>
<!--created by Kenny-->
<xsl:stylesheet version = &quot;1.0&quot; xmlns:xsl=&quot;[URL unfurl="true"]http://www.w3.org/TR/WD-xsl&quot;>[/URL]
<xsl:template match=&quot;/&quot;>
	<html>
	<head>
	
<script src=&quot; ../VerifyAndSubmit.js&quot;></script>
<script src=&quot; ../dateValidation.js&quot;></script>

<SCRIPT language=&quot;JavaScript&quot;>
	function openBrWindow(theURL,winName,features)
	{
	   window.open(theURL,winName,features);
  	}

   </SCRIPT>


	</head>
	
	<body bgcolor=&quot;#999999&quot; text=&quot;#000000&quot;>
	
	<!-- <xsl:apply-templates select=&quot;//CertificateModel&quot;/> -->
	
	<!--<xsl:template match=&quot;CertificateModel&quot;> -->

<center>

 <xsl:element name=&quot;Select&quot;>
					<xsl:attribute name=&quot;NAME&quot;>status</xsl:attribute>
					<xsl:attribute name=&quot;size&quot;>1</xsl:attribute>

								<xsl:element name=&quot;option&quot;>
									<xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;ID&quot;/></xsl:attribute>
									<xsl:attribute name=&quot;selected&quot;/>
									Kenneth Birney
								</xsl:element>
								<xsl:element name=&quot;option&quot;>
									<xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;ID&quot;/></xsl:attribute>
									<xsl:attribute name=&quot;selected&quot;/>
									Ross Birney
								</xsl:element>
								<xsl:element name=&quot;option&quot;>
									<xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;ID&quot;/></xsl:attribute>
									<xsl:attribute name=&quot;selected&quot;/>
									Robin Birney
								</xsl:element>
				</xsl:element>
				
<xsl:element name=&quot;input&quot;>
			<xsl:attribute name=&quot;class&quot;>longButton</xsl:attribute>
			<xsl:attribute name=&quot;type&quot;>button</xsl:attribute>
       		<xsl:attribute name=&quot;Value&quot;>Previous</xsl:attribute>
       		<xsl:attribute name=&quot;onclick&quot;>onClick=&quot;history.go(-1)&quot;</xsl:attribute>

       </xsl:element>


<xsl:element name=&quot;input&quot;>
			<xsl:attribute name=&quot;class&quot;>longButton</xsl:attribute>
			<xsl:attribute name=&quot;type&quot;>button</xsl:attribute>
       		<xsl:attribute name=&quot;Value&quot;>Next</xsl:attribute>
       		<xsl:attribute name=&quot;onclick&quot;></xsl:attribute>

       </xsl:element>




<br></br>

</center>		
	<xsl:element name=&quot;table&quot;>
				<xsl:attribute name=&quot;border&quot;>1</xsl:attribute>
				<xsl:attribute name=&quot;width&quot;>75%</xsl:attribute>
				<xsl:attribute name=&quot;align&quot;>center</xsl:attribute>
  <tr>
    <td height=&quot;63&quot;>
      <div align=&quot;center&quot;>
        <xsl:element name=&quot;table&quot;>
				<xsl:attribute name=&quot;border&quot;>0</xsl:attribute>
				<xsl:attribute name=&quot;width&quot;>75%</xsl:attribute>
				<xsl:attribute name=&quot;bordercolor&quot;>#CCCCCC</xsl:attribute>
				<xsl:attribute name=&quot;align&quot;>center</xsl:attribute>
				<xsl:attribute name=&quot;height&quot;>100%</xsl:attribute>
          <tr>
            
          </tr>
          <tr>
            <td height=&quot;29&quot; width=&quot;17%&quot;><b>Name:</b></td>
            <td height=&quot;29&quot; width=&quot;39%&quot;>
              <div align=&quot;left&quot;><font size=&quot;5&quot;><xsl:value-of select=&quot;/details/FirstName&quot;/></font>
              <font size=&quot;5&quot;><xsl:value-of select=&quot;/details/LastName&quot;/></font></div>
            </td>

            <td height=&quot;29&quot; width=&quot;20%&quot;><b>Date of Birth:</b></td>
            <td height=&quot;29&quot; width=&quot;24%&quot;><b> <font size=&quot;3&quot;><xsl:value-of select=&quot;/details/DateOfBirth&quot;/></font></b></td>
          </tr>
          <tr>
            <td width=&quot;17%&quot;><b>Address</b></td>
            <td colspan = &quot;3&quot;>
              <div align=&quot;left&quot;><font size=&quot;3&quot;><b><xsl:value-of select=&quot;/details/Address&quot;/></b></font></div>
            </td>
          </tr>
        </xsl:element>
      </div>
    </td>
  </tr>
</xsl:element>
<br/>
<center>

</center>


<form name=&quot;form&quot; method=&quot;post&quot; action=&quot;&quot;>
  <br/>
  <xsl:element name=&quot;table&quot;>
				<xsl:attribute name=&quot;border&quot;>0</xsl:attribute>
				<xsl:attribute name=&quot;width&quot;>75%</xsl:attribute>
				<xsl:attribute name=&quot;align&quot;>center</xsl:attribute>
    <tr>
      <td width=&quot;23%&quot; height=&quot;31&quot;>Title</td>
      <td width=&quot;25%&quot; height=&quot;31&quot;>
        <input type=&quot;text&quot; name=&quot;title&quot;>
        	<xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;/details/Title&quot;/></xsl:attribute>
		</input>
      </td>

  <td width=&quot;23%&quot;>Gender:</td>
      <td width=&quot;25%&quot;>



          <xsl:element name=&quot;Select&quot;>
					<xsl:attribute name=&quot;NAME&quot;>Gender</xsl:attribute>
					<xsl:attribute name=&quot;size&quot;>1</xsl:attribute>

								<xsl:element name=&quot;option&quot;>
									<xsl:attribute name=&quot;value&quot;>Male</xsl:attribute>
									<xsl:attribute name=&quot;selected&quot;/>
									Male
								</xsl:element>
								<xsl:element name=&quot;option&quot;>
									<xsl:attribute name=&quot;value&quot;>Female</xsl:attribute>
									<xsl:attribute name=&quot;selected&quot;/>
									Female
								</xsl:element>
				</xsl:element>
 
 
 
 
      </td>

     
    </tr>
    <tr>

    
 <td width=&quot;21%&quot; height=&quot;31&quot;>Last Name:</td>
      <td width=&quot;31%&quot; height=&quot;31&quot;>
        <input type=&quot;text&quot; name=&quot;lastName&quot;>
        	<xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;/details/LastName&quot;/></xsl:attribute>
		</input>
      </td>

<td width=&quot;21%&quot; height=&quot;31&quot;>First Name:</td>
      <td width=&quot;31%&quot; height=&quot;31&quot;>
        <input type=&quot;text&quot; name=&quot;firstName&quot;>
        	<xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;/details/FirstName&quot;/></xsl:attribute>
		</input>
      </td>

   
    </tr>
    <tr>

 <td width=&quot;23%&quot;>Other Last Name </td>
      <td width=&quot;25%&quot;>
        <input type=&quot;text&quot; name=&quot;otherLastName&quot;>
        	<xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;/details/OtherLastName&quot;/></xsl:attribute>
		</input>
      </td>


<td width=&quot;21%&quot; height=&quot;31&quot;>Other First Name:</td>
      <td width=&quot;31%&quot; height=&quot;31&quot;>
        <input type=&quot;text&quot; name=&quot;otherFirstName&quot;>
        	<xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;/details/OtherFirstName&quot;/></xsl:attribute>
		</input>
      </td>
</tr>


   
     
    <tr>
 




      <td width=&quot;21%&quot;>Preferred Name:</td>
      <td width=&quot;31%&quot;>
        <input type=&quot;text&quot; name=&quot;preferedName&quot;>
			<xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;/details/PreferedName&quot;/></xsl:attribute>
		</input>
      </td>

 

      <td width=&quot;21%&quot;>Date of birth:</td>
      <td width=&quot;31%&quot;>
        <input type=&quot;text&quot; name=&quot;dateOfBirth&quot;>
        	<xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;/details/DateOfBirth&quot;/></xsl:attribute>
		</input>
      </td>
    </tr>
<tr>

  <td width=&quot;23%&quot;>Nationality: </td>
      <td width=&quot;25%&quot;>
        <input type=&quot;text&quot; name=&quot;nationality&quot;>
       		 <xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;/details/Nationality&quot;/></xsl:attribute>
		</input>
      </td>


<td width=&quot;21%&quot; height=&quot;31&quot;>Occupation Code:</td>
      <td width=&quot;31%&quot; height=&quot;31&quot;>
        <xsl:element name=&quot;Select&quot;>
					<xsl:attribute name=&quot;NAME&quot;>Occupation</xsl:attribute>
					<xsl:attribute name=&quot;size&quot;>1</xsl:attribute>

								<xsl:element name=&quot;option&quot;>
									<xsl:attribute name=&quot;value&quot;>1002</xsl:attribute>
									<xsl:attribute name=&quot;selected&quot;/>
									1002
								</xsl:element>
								<xsl:element name=&quot;option&quot;>
									<xsl:attribute name=&quot;value&quot;>6061</xsl:attribute>
									<xsl:attribute name=&quot;selected&quot;/>
									6061
								</xsl:element>
				</xsl:element>
 
      </td>
    </tr>


<tr>
 <td width=&quot;21%&quot;>SCRO no:</td>
      <td width=&quot;31%&quot;>
        <input type=&quot;text&quot; name=&quot;scroNo&quot;>
       		 <xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;/details/SCRONumber&quot;/></xsl:attribute>
        </input>
      </td>
   


<td width=&quot;21%&quot; height=&quot;31&quot;>Driver No:</td>
      <td width=&quot;31%&quot; height=&quot;31&quot;>
        <input type=&quot;text&quot; name=&quot;driverNo&quot;>
        	<xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;/details/DriverNumber&quot;/></xsl:attribute>
		</input>
      </td>


</tr>

<tr>

<td width=&quot;21%&quot; height=&quot;31&quot;>Roles:</td>
      <td width=&quot;31%&quot; height=&quot;31&quot;>
      <xsl:element name=&quot;Select&quot;>
					<xsl:attribute name=&quot;NAME&quot;>Roles</xsl:attribute>
					<xsl:attribute name=&quot;size&quot;>1</xsl:attribute>

								<xsl:element name=&quot;option&quot;>
									<xsl:attribute name=&quot;value&quot;>Contact</xsl:attribute>
									<xsl:attribute name=&quot;selected&quot;/>
									Contact
								</xsl:element>
								<xsl:element name=&quot;option&quot;>
									<xsl:attribute name=&quot;value&quot;>App</xsl:attribute>
									<xsl:attribute name=&quot;selected&quot;/>
									App
								</xsl:element>
				</xsl:element>
 
      </td>




</tr>

    <tr>
      <td width=&quot;23%&quot;></td>
      <td width=&quot;25%&quot;></td>
      <td width=&quot;21%&quot;></td>
      <td width=&quot;31%&quot;></td>
    </tr>
    <tr>
      <td width=&quot;23%&quot;></td>
      <td width=&quot;25%&quot;></td>
      <tr></tr>
      <td width=&quot;23%&quot;></td>
     
      <td width=&quot;31%&quot;>
      
     
      
        
<xsl:element name=&quot;input&quot;>
			<xsl:attribute name=&quot;class&quot;>longButton</xsl:attribute>
			<xsl:attribute name=&quot;type&quot;>button</xsl:attribute>
       		<xsl:attribute name=&quot;Value&quot;>Add</xsl:attribute>
       		<xsl:attribute name=&quot;onclick&quot;>
											
			</xsl:attribute>
       </xsl:element>
       
       <xsl:element name=&quot;input&quot;>
			<xsl:attribute name=&quot;class&quot;>longButton</xsl:attribute>
			<xsl:attribute name=&quot;type&quot;>button</xsl:attribute>
       		<xsl:attribute name=&quot;Value&quot;>Del</xsl:attribute>
       		<xsl:attribute name=&quot;onclick&quot;>
											
			</xsl:attribute>
       </xsl:element>
          
<td colspan = &quot;3&quot;>
<xsl:element name=&quot;input&quot;>
			<xsl:attribute name=&quot;class&quot;>longButton</xsl:attribute>
			<xsl:attribute name=&quot;type&quot;>button</xsl:attribute>
       		<xsl:attribute name=&quot;Value&quot;>Incidents</xsl:attribute>
       		<xsl:attribute name=&quot;onclick&quot;>
											
			</xsl:attribute>
       </xsl:element>
     

       <xsl:element name=&quot;input&quot;>
			<xsl:attribute name=&quot;class&quot;>longButton</xsl:attribute>
			<xsl:attribute name=&quot;type&quot;>button</xsl:attribute>
       		<xsl:attribute name=&quot;Value&quot;>Application</xsl:attribute>
       		<xsl:attribute name=&quot;onclick&quot;>
											
			</xsl:attribute>
       </xsl:element>


 <xsl:element name=&quot;input&quot;>
			<xsl:attribute name=&quot;class&quot;>longButton</xsl:attribute>
			<xsl:attribute name=&quot;type&quot;>button</xsl:attribute>
       		<xsl:attribute name=&quot;Value&quot;>Certificates</xsl:attribute>
       		<xsl:attribute name=&quot;onclick&quot;>
											
			</xsl:attribute>
       </xsl:element>
</td>
</td>
    </tr>
    <tr>
      <td width=&quot;23%&quot;></td>
      <td width=&quot;25%&quot;></td>
      <td width=&quot;21%&quot;></td>
      <td width=&quot;31%&quot;></td>
    </tr>
    <tr>
      <td width=&quot;23%&quot; height=&quot;34&quot;></td>

      <td colspan=&quot;2&quot;>
        <div align=&quot;right&quot;>
        

         
        </div>
      </td>
      <td width=&quot;31%&quot; height=&quot;34&quot;>
			
       </td>
    </tr>
  </xsl:element>
  <br/>
  <br/>
</form>
</body>
	</html>
</xsl:template>
</xsl:stylesheet>

thanks for your help

Kenneth Birney
User Interface Programmer
Scottish Police
 
Hi Kenneth,

Perhaps you can use a input parameter for your xsl, specifying the person you wish to view. By default the value of this parameter will be 1 (being the first person node).
Code:
<xsl:stylesheet version = &quot;1.0&quot; xmlns:xsl=&quot;[URL unfurl="true"]http://www.w3.org/TR/WD-xsl&quot;;>[/URL]
<xsl:parameter name=&quot;SelectedPerson&quot;>1</xsl:parameter>
[\code]

Now you can create a variabel which contains only the person node you wich to interrogate ;-)

[code]
<xsl:variable name=&quot;PersonToInterrogate&quot; select=&quot;details/person[$SelectedPerson]&quot;/>
[\code]

I notice that you use the namespace ...WD-xsl. Probably because you want to perform a client-side transformation.... I'm afraid my code might not work because the namespace doesn't support the xsl:parameter tag on the stylesheet tag.

Another option then would be to do it all in javascript with use of the Domdocument object.

Good luck!!

Jordi Reineman
Cap Gemini Ernst & Young
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top