Subject: Re: [xsl] Newbie question on Recusrion using XLST 1.0 Part 2 From: omprakash.v@xxxxxxxxxxxxx Date: Mon, 2 May 2005 09:17:16 +0530 |
Hi, If you'd like the template to be called based on some condition, then the call to the template should occur inside the region where the condition evaluates to true. I have modified your code to demonstrate this below: <xsl:choose> <xsl:when test="$employeeList/employees/employee[position() > 1]"/> <!--Get the remaining employee EID attributes --> <xsl:call-template name="DisplayEmployees"> <xsl:with-param name="employeeList" select="$employeeList[position() > 1]"/> </xsl:call-template> <!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Note I have moved the call-template inside the xsl:choose --> </xsl:choose> Though in you case, there doesn't appear to be any need to perform this check. Also, the above comment on your code doesn't mean that Iam recommending this approach. Cheers, Omprakash.V "Marco Mastrocinque" To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> <mmfive@netspa cc: (bcc: omprakash.v/Polaris) ce.net.au> Subject: [xsl] Newbie question on Recusrion using XLST 1.0 Part 2 05/02/2005 06:51 AM Please respond to xsl-list 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() > 1]"/> </xsl:choose> <!--Get the remaining employee EID attributes --> <xsl:call-template name="DisplayEmployees"> <xsl:with-param name="employeeList" select="$employeeList[position() > 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 This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately. You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification, distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited. Visit Us at http://www.polaris.co.in
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Newbie question on Recusrion , Marco Mastrocinque | Thread | RE: [xsl] Newbie question on Recusr, Aron Bock |
[xsl] Newbie question on Recusrion , Marco Mastrocinque | Date | [xsl] Rowspan and colspan, Danilo Fanchi |
Month |