Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] Newbie question on Recusrion using XLST 1.0 Part 2

From: "Marco Mastrocinque" <mmfive@--------------->
To:
Date: 5/2/2005 1:22:00 AM
Hi All,
       Following from my previous email. I have updated my code to no avail.
Again I won't to display each EID attribute for each employee grouped by
division, using XSLT version 1.0.

Any suggestions most appreciated.

Thanks Marco Mastrocinque 

 
<xsl:variable name="result">
   <xsl:call-template name="DisplayEmployees">
	<xsl:with-param name="employeeList" select="company/division"/>
   </xsl:call-template>
</xsl:variable>								
<br/>
<h3>The value of result is <xsl:value-of select="$result"/></h3>	
	

</xsl:template>
    <xsl:template name="DisplayEmployees">
    <!--This is a recursive routine-->
    <xsl:param name="employeeList"/>
	 <xsl:choose>
	    <xsl:when test="not($employeeList)">
	    <!--If the nodelist is empty return true-->
		 <xsl:text>true</xsl:text>
	    </xsl:when>
	    <xsl:otherwise>
		<xsl:choose>
		<!--Get the first employee EID attribute -->
		<xsl:when test="$employeeList/employees/employee[1]">
		  <xsl:value-of select="@EID"/>	
		</xsl:when>
		<xsl:otherwise>
		<!--Get the remaianing EID attributes -->
		<xsl:choose>
		  <xsl:when
test="$employeeList/employees/employee[position() &gt; 1]"/>
		  </xsl:choose>
		  <!--Get the remaining employee EID attributes -->
		  <xsl:call-template name="DisplayEmployees">
			<xsl:with-param name="employeeList"
select="$employeeList[position() &gt; 1]"/>
		  </xsl:call-template>
	     </xsl:otherwise>
	  </xsl:choose>
	 </xsl:otherwise>
      </xsl:choose>
    </xsl:template>       		
</xsl:stylesheet>


-----Original Message-----
From: Marco Mastrocinque [mailto:mmfive@xxxxxxxxxxxxxxx] 
Sent: Saturday, 30 April 2005 5:16 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Newbie question on Recusrion using XLST 1.0

Hi All,
       I have an example file with the following structure:

<company>
   <division DID="Sal">
      <employees>
		<employee EID="EMP001">
		   <ENAME>Joe Blow</ENAME>
               <OFFICE>1.2.27</OFFICE>
               <BIRTHDATE>1963-08-01</BIRTHDATE>
		   <SALARY>28790</SALARY>	  	
		</employee>	
		<employee EID="EMP002">
		   <ENAME>John Doe</ENAME>
               <OFFICE>1.2.2</OFFICE>
               <BIRTHDATE>1970-08-01</BIRTHDATE>
		   <SALARY>29855</SALARY>	  	
		</employee>	
	</employees>	
   </division>
   <division DID="SOF">
      <employees>
		<employee EID="EMM001">
		   <ENAME>Mark Smith</ENAME>
               <OFFICE>1.2.27</OFFICE>
               <BIRTHDATE>1966-08-01</BIRTHDATE>
		   <SALARY>35000</SALARY>	  	
		</employee>	
		<employee EID="EMM002">
		   <ENAME>John Doe</ENAME>
               <OFFICE>1.2.2</OFFICE>
               <BIRTHDATE>1977-08-01</BIRTHDATE>
		   <SALARY>40000</SALARY>	  	
		</employee>	
	</employees>	
   </division>	
</company>



I'm having using a recursive routine (see below) to display the following
elements and attributes:
1) The employee EID attribute such as 'EMP001', followed by
2) The element text of ENAME, such as 'Joe Blow',
3) The element text of OFFICE, such as '1.2.27'
4) The output must be formatted such that the employees of each division are
grouped together.

Here is my code so far, for the above snippet of XML code which has numerous
errors:

<xsl:variable name="result">
  <xsl:call-template name="DisplayEmployees">
	<xsl:with-param name="employeeList" select="company/division"/>
  </xsl:call-template>
</xsl:variable>	
<xsl:value-of select="$result"/>		


<xsl:template name="DisplayEmployees">
    <!--This is a recursive routine-->
		<xsl:param name="employeeList"/>
		<xsl:choose>
			<xsl:when test="not($employeeList)">
			    <!--If the nodelist is empty return true-->
				<xsl:text>true</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when
test="employees/employee[@EID]">
						<xsl:value-of
select="@EID"/>	
					</xsl:when>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
    </xsl:template>

I can't seem to get any output. Trying to put it in a html file. Please note
I'm new to XSLT and XPATH so please excuse the numerous errors.

Thanks Marco Mastrocinque


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent