RE: [xsl] Problem for : increment a variable in a for-each?

Subject: RE: [xsl] Problem for : increment a variable in a for-each?
From: que Li <queincanada@xxxxxxxx>
Date: Mon, 29 Nov 2004 13:03:22 -0500 (EST)
Hi Mike:
   Thanks. I think you understand most of my
explanation.

But the count is still 5 not 3
 
I try to copy my xsl and xml file .I wish code is
readable this time and you can understand all.


the exactly result which I want is: 
A( C and D); B and E

but what I have now:
A ( C and D ) and B ;E

the reason that I need find the position() then I can
decide if I need display title by one of three format:
format 1) directly display title (first position) 

format 2) add  ";" after title if the title is not the
first and not the last() -1  

format 3) and "and" before title if the title is
last()-1 

Problem: for <List_ID>11 and <list_ID>14 .position()
is 4 and 5( How I can get the position() is 2 and 3)

XML file:
<Lists>
<List>
  <List_ID>10</List_ID>
   <Title>A</Title>
  <Parent_ID>1</Parent_ID>
 </List>
 <List>
   <List_ID>12</List_ID>
   <Title>C</Title>
    <Parent_ID>10</Parent_ID>
 </List>
 <List>
   <List_ID>13</List_ID>
   <Title>D</Title>
   <Parent_ID>10</Parent_ID>
 </List>
  <List>
   <List_ID>11</List_ID>
    <Title>B</Title>
   <Parent_ID>1</Parent_ID>
 </List>
 <List>
    <List_ID>14</List_ID>
   <Title>E</Title>
  <Parent_ID>15</Parent_ID>
 </List>
  </Lists>


XSL:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; >

<xsl:template match="Lists"  >
Test count: <xsl:value-of select="count(List[Parent_ID
= 1 or not(List[List_id  = current()/Parent_ID])])"/>
  		 
<xsl:apply-templates  select="List[Parent_ID = 1 or
not(List[List_id  = current()/Parent_ID])]"/>
 </xsl:template>		

<xsl:template match="List" >
<xsl:choose>
<xsl:when test="Parent_ID=1">  
<xsl:choose>
<xsl:when test="position()=1">
  <br/><b><xsl:value-of select="Title"/></b>
</xsl:when>
<xsl:when test="position()=last()-1">
  <b> and <xsl:value-of select="Title"/></b>
</xsl:when>
<xsl:otherwise>
  <b> ;<xsl:value-of select="Title"/></b>
</xsl:otherwise>
</xsl:choose>  
<xsl:call-template name="findChildNode">
<xsl:with-param name="ParentID" select="List_ID"/>
</xsl:call-template> 
 </xsl:when> 
 <xsl:otherwise>
<xsl:call-template name="findParentNode">
<xsl:with-param name="ID" select="Parent_ID"/>
</xsl:call-template> 
</xsl:otherwise>  
</xsl:choose>                   
</xsl:template> 

<xsl:template name="findChildNode">
<xsl:param name="ParentID"/>
<xsl:for-each select="../List[Parent_ID=$ParentID]">
    <xsl:choose>
<xsl:when test="position()=1 and last() &gt;2 ">
  <b> ( <xsl:value-of select="Title"/></b>
</xsl:when>
<!--only one-->
<xsl:when test="position()=1 and last()=1">
<b> ( <xsl:value-of select="Title"/> )</b>
</xsl:when>
<!--only two-->
<xsl:when test="position()=1 and  last()=2 ">
<b> ( <xsl:value-of select="Title"/> </b>
</xsl:when>
<xsl:when test="position()!=1 and position()=last()">
<b> and <xsl:value-of select="Title"/> )</b>          
    
</xsl:when>
<xsl:otherwise>
<b> ; <xsl:value-of select="Title"/></b>           
</xsl:otherwise> 
</xsl:choose> 	       
</xsl:for-each>
</xsl:template>

<xsl:template name="findParentNode" >
    <xsl:param name="ID"/>
<xsl:if  test="count(../List[List_ID=$ID]) = 0"> 
<xsl:choose>
<xsl:when test="position()=1">
 <b><xsl:value-of select="Title"/></b>
</xsl:when>
<xsl:when test="position()=last()-1">
<b> and  <xsl:value-of select="Title"/></b>
</xsl:when>
<xsl:otherwise>
<b> ;<xsl:value-of select="Title"/></b>
</xsl:otherwise>
</xsl:choose>  			
</xsl:if>    
</xsl:template>
</xsl:stylesheet>


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

Current Thread