RE: [xsl] four time post:

Subject: RE: [xsl] four time post:
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 26 Nov 2004 10:10:50 -0000
> What I want do: I need do different thing  for the 
> node which  parentID is 21(by passing in )(exampel:If
> it is first child then I need bold. if not first and
> not last one then I need do second thing. If the node
> is last child then I need do third things.

This seems a clear functional description of your problem and it doesn't
seem to involve variables or counting. Your code has come out very badly
formatted so it's difficult to see what's wrong with it. But the natural
XSLT solution to your problem is a set of template rules:

<xsl:template match="list[parentID='21'][1]" priority="2">
  <bold>...</bold>
</xsl:template>

<xsl:template match="list[parentID='21']" priority="1">
  <second-thing/>
</xsl:template>

<xsl:template match="list[parentID='21'][last()]" priority="2">
  <third-thing/>
</xsl:template>

Then you just apply-templates to a <list> element and the appropriate rule
gets invoked.

Michael Kay
http://www.saxonica.com/


> 
> I try to use the call:template and xsl:for each to
> pass the parameter but the count is always set to
> initial since I run so many for each 
> what I shoud do ?
> 
> My code
> 
> 
> <xsl:template match="root">
> 
> <xsl:for each select="list">
> 
> <xsl:if test="parented =1">
> 
> <xsl:call-template name= !0findChildNode!1>
> 
>   <xsl:with-param name=!1ID!1 select="ID!1/>
> 
> </xsl:call-template>
> 
> </xsl:for-each>
> 
> </xsl:template>
> 
> 
> 
> <xsl:template name="findChildNode!1>
> 
> <xsl:param name="ID!1>
> 
> <xsl:param name="count!1 select="0!1/>
> 
> <xsl:for-each select="../list!1>
> 
>    <xsl:if test="parentID=$ID!1>
> 
>     <xsl:call-template  name="formatChild!1>
> 
> <xsl:with-param name="count" select="$count+1!1/>
> 
>    </xsl:if>
> 
> </xsl:for each>
> 
> </xsl:template>
> 
> 
> 
> <xsl:template name="formatChid!1>
> 
>    <xsl:param name="count!1>
> 
> <xsl:variable name="TotalChildCount!1 select=!1?!1/>
> (Note: I don't know how I can get all child node count
> based on the one parentID)
> 
>             <xsl:choose>
> 
> <xsl:when  test="$count=1!1>do firsth thing</xsl:when>
> <xsl:when  test="$count &gt; 1 and $count &lt; 
> $TotalChildCount!1>do second  thing</xsl:when>
> 
> <xsl:when  test="$count=$TotalCount!1>do third 
> thing</xsl:when>
> 
>           </xsl:choose>
> 
> </xsl:template>
> 
> 
> 
> Question: 
> 
>  1.   Why every time the $count is 0 and never
> incresement  ?
> 2.   How I can get the total child count value based
> on the parent ID?
> 
> Thanks for any help
> Helena
> 
> 
> ______________________________________________________________
> ________ 
> Post your free ad now! http://personals.yahoo.ca

Current Thread