[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Problem for : increment a variable in a for-each?

Subject: RE: Problem for : increment a variable in a for-each?
From: que Li <queincanada@xxxxxxxx>
Date: Fri, 26 Nov 2004 19:17:12 -0500 (EST)
xsl increment variable
Hi Andrew:

   Thanks for help.
   I update xsl file using the template now I have
figure out most of them except that one problems.How I
can find the current node position inside the correct
group?


my XSL file:
<xsl:template match="SubjectLists">
           <xsl:apply-templates />
         </xsl:template>		
       <xsl:template match="Subject_List" >
       <xsl:choose>
			<xsl:when test="Subject_Parent_ID=1">
				                    <xsl:choose>
											<xsl:when
test="not(preceding-sibling::Subject_List)">
		                                        
<b><xsl:value-of select="Subject_Title"/></b>
											</xsl:when>
											<xsl:when
test="not(following-sibling::Subject_List)">
											       <b> ;<xsl:value-of
select="Subject_Title"/></b>
											</xsl:when>
											<xsl:otherwise>
												   <b> and  <xsl:value-of
select="Subject_Title"/></b>
											</xsl:otherwise>
                                 </xsl:choose>  
                                   <xsl:call-template
name="findChildNode">
										   <xsl:with-param name="ParentID"
select="Subject_ID"/>
                                  </xsl:call-template>

                     </xsl:when> 
                     <xsl:otherwise>
                          <xsl:call-template
name="findParentNode">
                                  <xsl:with-param
name="ID" select="Subject_Parent_ID"/>
                          </xsl:call-template> 
                    </xsl:otherwise>  
            </xsl:choose>                   
	</xsl:template> 
	<xsl:template name="findChildNode">
	       <xsl:param name="ParentID"/>
	           <xsl:for-each
select="../Subject_List[Subject_Parent_ID=$ParentID]">
                     <xsl:choose>
                              <xsl:when
test="position()=1 and last() &gt;2 ">
							         <b> ( <xsl:value-of
select="Subject_Title"/></b>
			                  </xsl:when>
			                      <!--only one-->
							 <xsl:when test="position()=1 and last()=1">
							         <b> ( <xsl:value-of
select="Subject_Title"/> )</b>
			                  </xsl:when>
			                  <!--only two-->
			                  <xsl:when test="position()=1 and 
last()=2 ">
							         <b> ( <xsl:value-of
select="Subject_Title"/> </b>
			                  </xsl:when>
			                  <xsl:when test="position()!=1 and
position()=last()">
                                           <b> and
<xsl:value-of select="Subject_Title"/> )</b>          
    
			                  </xsl:when>
			                   <xsl:otherwise>
			                         <b> ; <xsl:value-of
select="Subject_Title"/></b>           
			                  </xsl:otherwise> 
					</xsl:choose> 	       
	        </xsl:for-each>
	</xsl:template>
	<xsl:template name="findParentNode" >
	       <xsl:param name="ID"/>
	      		 <xsl:if 
test="count(../Subject_List[Subject_ID=$ID]) = 0">
	      		      <xsl:choose>
								<xsl:when
test="not(preceding-sibling::Subject_List)">
		                                        
<b><xsl:value-of select="Subject_Title"/></b>
								</xsl:when>
								<xsl:when
test="not(following-sibling::Subject_List)">
											       <b> ;<xsl:value-of
select="Subject_Title"/></b>
								</xsl:when>
								<xsl:otherwise>
												   <b> and  <xsl:value-of
select="Subject_Title"/></b>
				    			</xsl:otherwise>
				     </xsl:choose>  			
			      </xsl:if>    
	 </xsl:template>   
XML file:
 <root>
<SubjectLists>
   <Subject_List>
  		<Subject_ID>31</Subject_ID> 
  		<Subject_Title>Biology</Subject_Title> 
  		<Subject_Parent_ID>30</Subject_Parent_ID> 
</Subject_List>
  <Subject_List>
  		<Subject_ID>32</Subject_ID> 
<Subject_Title>Chemistry</Subject_Title> 
<Subject_Parent_ID>30</Subject_Parent_ID> 
 </Subject_List>
   <Subject_List>
  		<Subject_ID>24</Subject_ID> 
<Subject_Title>Legal Studies</Subject_Title> 
<Subject_Parent_ID>1</Subject_Parent_ID> 
  </Subject_List>
 <Subject_List>
  		<Subject_ID>17</Subject_ID> 
<Subject_Title>Music</Subject_Title> 
<Subject_Parent_ID>14</Subject_Parent_ID> 
  </Subject_List>
     <Subject_List>
  		<Subject_ID>30</Subject_ID> 
  		<Subject_Title>Science</Subject_Title> 
  		<Subject_Parent_ID>1</Subject_Parent_ID> 
  </Subject_List>
    <Subject_List>
  <Subject_ID>18</Subject_ID> 
  <Subject_Title>Visual Arts</Subject_Title> 
  		  <Subject_Parent_ID>14</Subject_Parent_ID> 
 </Subject_List>
  </SubjectLists>
</root>



Now the result is:

and Legal Studies and Music and Science ( Biology and
Chemistry ) ;Visual Arts 


the correct result should be:

Legal Studies ; Music ; Science ( Biology and
Chemistry ) and Visual Arts 

the reason thst wrong resut is that the 

preceding-sibling::Subject_List 
following-sibling::Subject_List

should be one group ( That gourp include all node
whihc subject_parent_ID is 1  or subject_parent_ID is
not one but its parent didn;t exsit(example
node:subject_ID is 17 and subject_ID is 18)

Thanks
Helena




______________________________________________________________________ 
Post your free ad now! http://personals.yahoo.ca

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.